0
我用这个测试正确的实例变量设置喜欢:测试实例变量分配
it { should assign_to(:resource) }
我找不到它的任何更https://github.com/thoughtbot/shoulda-matchers。
我怎样才能找回它或写我自己的匹配器?
他们为什么将其删除?似乎对我有用。
我用这个测试正确的实例变量设置喜欢:测试实例变量分配
it { should assign_to(:resource) }
我找不到它的任何更https://github.com/thoughtbot/shoulda-matchers。
我怎样才能找回它或写我自己的匹配器?
他们为什么将其删除?似乎对我有用。
这里有一个快速匹配我在几分钟内扔在一起:
RSpec::Matchers.define :set_the_instance_variable do |instance|
match do |actual|
@actual = controller.instance_variable_get(instance)
@actual == @value
end
failure_message_for_should do |actual|
"Expected '#{instance}' to equal #{@value}. However, it did not: \n '#{@actual.inspect}' \n '#{@value.inspect}'"
end
failure_message_for_should_not do |actual|
"Expected '#{instance}' to not equal #{@value}. However, it did: \n '#{@actual.inspect}' \n '#{@value.inspect}'" end
description do
"'#{instance}' should equal #{@value}."
end
def to(value)
@value = value
self
end
end
使用
it { should set_the_instance_variable(:@folder).to(parent_folder)}
如果这个变量从您的公共接口是不是有在测试中它是没有意义的。如果你有一个accesor它可以使用respond_to
结合eq
检查值是否正确设置。