ruby most_profitable_orders_query_spec.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby most_profitable_orders_query_spec.rb相关的知识,希望对你有一定的参考价值。

# Poor specs
# ==========

# Customer relation is irrelevant in this case. Same as each order's subject.
# `match_array` expectation verifies count implicitly, so additional check seems obsolete.
describe MostProfitableOrdersQuery do
  describe '.call' do
    it 'returns top 50% orders with the biggest total value' do
      customer = create(:customer, name: 'Tony stark')
      create(:order, customer: customer, subject: 'Iron armor', total_value: 1000)
      most_profitable_order_1 =
        create(:order, customer: customer, subject: 'Dual laser glove', total_value: 1200)
      most_profitable_order_2 =
        create(:order, customer: customer, subject: 'Power cells', total_value: 1500)
      create(:order, customer: customer, subject: 'Sensor array', total_value: 500)

      result = MostProfitableOrdersQuery.call

      expect(result).to be_kind_of(ActiveRecord::Relation)
      expect(result.count).to eq(2)
      expect(result).to match_array(most_profitable_order_1, most_profitable_order_2)
    end
  end
end

# Good specs
# ============

# Only data important from test's perspective is provided.
describe MostProfitableOrdersQuery do
  describe '.call' do
    it 'returns top 50% orders with the biggest total value' do
      create(:order, total_value: 1000)
      most_profitable_order_1 = create(:order, total_value: 1200)
      create(:order, total_value: 500)
      most_profitable_order_2 = create(:order, total_value: 1500)

      result = MostProfitableOrdersQuery.call

      expect(result).to be_kind_of(ActiveRecord::Relation)
      expect(result).to match_array(most_profitable_order_1, most_profitable_order_2)
    end
  end
end

以上是关于ruby most_profitable_orders_query_spec.rb的主要内容,如果未能解决你的问题,请参考以下文章

Ruby 25 岁了!Ruby 之父说 Ruby 3 有望 3 倍提速

如何学习ruby?Ruby学习技巧分享

ruby Ruby脚本,看看是否用openssl编译了ruby

什么是ruby?

ruby和ruby ee

ruby入门知识:了解ruby历史及特性