对于rspec更改为使用expect().to而不是.should,我将如何更改以下内容:
...
describe '#push_state' do
def process(klass)
state = OpenStruct.new(:namespace => "ROOT", :scope => :instance, :owner => "ROOT")
klass.new(state, nil).process
end
it "should push and return all old state info after block" do
class PushStateHandler1 < Handlers::Base
def process
push_state(:namespace => "FOO", :scope => :class, :owner => "BAR") do
namespace.should == "FOO"
scope.should == :class
owner.should == "BAR"
end
namespace.should == "ROOT"
owner.should == "ROOT"
scope.should == :instance
end
end
...我的每一个变种都失败了,通常是用undefined method expect for #<PushStateHandler1:0x000000010a3470>
例如,我尝试过:
expect(namespace).to eq "FOO"
expect{(namespace) eq "FOO"}.to be_true发布于 2013-11-18 12:04:07
在it块的作用域中定义expect方法。在本例中,您在该块中定义了一个类,在该类中定义了一个实例方法,并在该实例方法中定义了一个块。我不知道具体的Ruby作用域规则,但是内部块中的变量不会在外部块的作用域中解释也就不足为奇了。should方法之所以起作用,是因为它是在Object上定义的。
因此,为了回答您的问题,我不知道如何将should转换为expect,只是说您必须以某种方式传递并使用外部块中的绑定来计算您尝试使用的任何expect表达式。
https://stackoverflow.com/questions/20038236
复制相似问题