Ruby rspec";它";一串
rspec方法是否可以在本地方法中获取传递给它()的参数值?例如,如果我想要:Ruby rspec";它";一串,ruby,rspec,Ruby,Rspec,rspec方法是否可以在本地方法中获取传递给它()的参数值?例如,如果我想要: describe Me do it "should figure this out" puts "I " + SPEC_NAME end end 要打印此文件: I should figure this out 。。。在代码示例中,我应该为SPEC_名称添加什么 更妙的是,像我这样的一位相对较新的红土学家会如何独自解决这个问题呢 description方法应该满足您的需要。e、 g describ
describe Me do
it "should figure this out"
puts "I " + SPEC_NAME
end
end
要打印此文件:
I should figure this out
。。。在代码示例中,我应该为SPEC_名称添加什么
更妙的是,像我这样的一位相对较新的红土学家会如何独自解决这个问题呢 description方法应该满足您的需要。e、 g
describe Me do
it "should figure this out" do
puts "I " + description # or "I #{description}" using string interpolation
end
end
关于如何解决这个问题,我在中找到了它,首先查看方法的源代码,看看它是如何工作的。然后,您将发现RSpec将“it”字符串引用为“description”,因此您可以查找名称中包含description的可用方法
我知道它现在对您没有多大用处,但随着您对Ruby的了解,您会发现阅读像RSpec这样的库中的代码会更容易,并且会对它们的实现方式产生直觉,这将帮助您在正确的位置查找东西。这并不能准确回答您的问题,但是,如果您试图在每个测试运行时打印出来,请将其放入
spec.opts
文件中:--格式specdoc
下面是一个示例,说明了我运行测试时的情况:
A new release when parsing the artist containing a full join word
- should remove it
- should not remove it when it is inter-word
A new release when parsing the artist containing an abbreviated joining word
- should remove it when there is a period after it
- should remove it when when there is not a period after it
- should not remove it when it is inter-word with a period after it
- should not remove it when it is inter-word without a period after it
A new release when parsing the artist
- should be invalid if the year is not current
- should be valid if it is the current year
对于RSpec的最新版本(我使用的是2.14),您可以将其称为
示例。description
it "prints itself" do
puts "My description string is '#{example.description}'."
end
不完全是我想要的,但还是很好的小费!我试过使用RSpec2.8.0,但它没有立即起作用。这是在什么物体上运行的?我发现:RSpec::ExampleGroup::Nested_2(我想这对你来说是ExampleGroup)我的解决方案是:example.description+1,其中包括如何从源代码/文档中找出类似问题的说明。