RSpec2& Rails3,问题是测试助手的基础知识

时间:2011-02-21 20:31:29

标签: ruby-on-rails helper rspec2

这当然是微不足道的,但无法弄清楚出了什么问题。

助手:app / helpers / bookings_helper.rb

module BookingsHelper
  def booking_price(booking)
    "something"
  end
end

帮助规范:spec / helpers / bookings_helper_spec.rb

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe BookingsHelper do
  describe "#booking_price" do
    helper.booking_price.should == 'something'
  end
end

错误

/Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `booking_price' for nil:NilClass (NoMethodError)

1 个答案:

答案 0 :(得分:2)

尝试使用它代替内部块的描述:

describe BookingsHelper do
  it "#booking_price" do
    helper.booking_price.should == 'something'
  end
end