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
檢查值是否正確設置。