未定义的方法`to_sym' 1:Fixnum或rspec测试

时间:2016-07-19 21:08:16

标签: ruby rspec

对于rspec测试我收到以下错误但是弄清楚如何解决它:

1) Promotion_Check#initialize starts with a list of the rules
   Failure/Error: rules_list = double( { 1 => item_rule, 2 => total_rule } )

   NoMethodError:
     undefined method `to_sym' for 1:Fixnum
   # ./spec/Promotion_Check_spec.rb:10:in `block (3 levels) in <top (required)>'

以下是测试:

require 'spec_helper'

describe Promotion_Check do


  describe "#initialize" do
    it "starts with a list of the rules" do
      item_rule = double({rule_type: "item", item_code: 1, number_of_items: 2, new_item_price: 8.50})
      total_rule = double( {rule_type: "total", total_price_break: 60.00, discount_percentage: 10} )
      rules_list = double( { 1 => item_rule, 2 => total_rule } )
      let(:check) { Promotion_Check.new rules_list }
      expect(check.rules_list).to eq( { 1 => item_rule, 2 => total_rule } )
    end
  end
end

我将测试的是什么:

class Promotion_Check

  attr_reader :rules_list

  def initialize rules_list = {}
    @rules_list = rules_list
  end
end

任何帮助都会非常感谢。

1 个答案:

答案 0 :(得分:0)

修正了以下内容:

require 'spec_helper'

describe Promotion_Check do

  let(:check) { Promotion_Check.new rules_list }
  let(:item_rule) { {rule_type: "item", item_code: 1, number_of_items: 2, new_item_price: 8.50} }
  let(:total_rule)  { {rule_type: "total", total_price_break: 60.00, discount_percentage: 10} }
  let(:rules_list) { [ 1 => item_rule, 2 => total_rule ] }

  describe "#initialize" do
    it "starts with a list of the rules" do
      expect(check.rules_list).to eq( [ 1 => item_rule, 2 => total_rule ] )
    end
  end

由于