我是Ruby的新手,无法从这里获得任何答案,因为代码级别在这里看起来非常先进:
How do I pass multiple arguments to a ruby method as an array?
我创建了一个这样的step_definitions:
Then(/^I should see "([^"]*)" as the name for line item (.*)$/) do |puppy_name, line_item|
@cart.name_for_line_item line_item
end
其中方法name_for_line_item
仅采用一个参数,即line_item
但在上面的step_definition中,我必须验证我正在传递的puppy_name
。
所以我试过了:
@cart.name_for_line_item.should include puppy_name line_item
但这是方法下的红线错误
如果我尝试
@cart.name_for_line_item line_item .should include puppy_name
它给出了编译时错误:
RSpec::Expectations::ExpectationNotMetError
来源:Jeff Morgan的黄瓜和奶酪
答案 0 :(得分:1)
你应该使用括号:
(@cart.name_for_line_item(line_item).should).include? puppy_name
最新版本的rspec允许另一种语法:
expect(@cart.name_for_line_item(line_item)).to include(puppy_name)
链接到rspec文档:https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers