如何测试使用捕获的辅助方法?

时间:2012-07-20 21:35:05

标签: ruby-on-rails testing rspec helpers

我有一个帮助者执行:

def send_to_block(value, &block)
   capture(value, &block)
end

编写测试时:

value_received = nil
send_to_block('test') do |value|
   value_received = value
end
value_received.should == 'test'

我收到以下异常:

NameError: uninitialized constant Kernel::DISABLED

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

您将要使用辅助对象,如:https://www.relishapp.com/rspec/rspec-rails/v/2-11/docs/helper-specs/helper-spec

中所述

这些方面应该是你所追求的:

require "spec_helper"

describe MyHelper do
  describe "#send_to_block" do
    it "should do something" do
      helper.send_to_block('test').should == 'I have no idea what this should be'
    end
  end
end