这是通过运行使用共享规范组的整个规范套件获得的示例回溯
8)
RuntimeError in 'Arel Join#each iterates over the rows in any order'
/Users/apatterson/git/arel/spec/../lib/arel/algebra/relations/operations/join.rb:14:in `hash'
/Users/apatterson/git/arel/spec/../lib/arel/session.rb:38:in `[]'
/Users/apatterson/git/arel/spec/../lib/arel/session.rb:38:in `read'
/Users/apatterson/git/arel/spec/../lib/arel/algebra/relations/relation.rb:21:in `each'
/Users/apatterson/git/arel/spec/support/matchers/have_rows.rb:5:in `have_rows'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/matchers/simple_matcher.rb:16:in `call'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/matchers/simple_matcher.rb:16:in `matches?'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/expectations/handler.rb:11:in `handle_matcher'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/expectations/extensions/kernel.rb:27:in `should'
/Users/apatterson/git/arel/spec/shared/relation_spec.rb:23:
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:40:in `instance_eval'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:40:in `execute'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:53:in `timeout'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_methods.rb:37:in `execute'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:214:in `run_examples'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `each'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:212:in `run_examples'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/example/example_group_methods.rb:103:in `run'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:23:in `run'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `each'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/example_group_runner.rb:22:in `run'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/options.rb:152:in `run_examples'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run'
/Library/Ruby/Gems/1.8/gems/rspec-1.3.0/bin/spec:5
这里有几个问题。
1) 鉴于回溯,我不知道共享规范的上下文是什么。 又名,它包含在哪里,它包含在哪个文件中,等等......有描述“Arel Join#each 以任何顺序迭代行”,但在一个有很多规范的项目中,这基本上没用我。
2)我想要一种在导致它失败的上下文中单独运行该单个规范的方法。 我现在不知道该怎么做。
大卫,我想我可能有一个解决方案:
当“it_should_behave_like”(或别名)被调用时,它会在 ExampleGroup 上设置以下元数据:
共享示例组的名称。
“it_should_behave_like”方法调用的文件路径和行号。
当示例失败时,RSpec 将检查该示例是否存在于共享示例组中。 如果是,它会将文件路径和行号(存储在 ExampleGroup 元数据中)附加到输出中。
你怎么认为?
哦,太好了,我看到元数据已经存在了:-)
补丁: http :
我合并了@justinko的补丁 (3906559d059bcdbd4d15303303c517088b038eeb),它显示了调用共享组的行,所以我们现在知道它运行的上下文。 这仍然存在运行单个共享示例的问题 - 但这至少应该有助于理解共享示例何时失败。
您可以通过rspec spec/my_spec_that_contains_the_shared_group.rb --example "hello world"
在共享组中运行单个示例
是的 - 这是真的。 这对我来说已经足够了。 我要关闭这个。 @carllerche如果您认为这还不够,请在此处发表评论,我将重新打开此内容。
废话,发现了一个错误:
share_as :MySpecs do
let(:foo) { described_class # returns nil }
调查。
我想弃用 share_as。 它生成一个模块,然后您使用include
将其包含在内,这与创建嵌套组的含义非常不同,就像我们现在使用shared_examples_for
所做的那样。 WDYT?
我完全同意弃用它。 当我第一次开始学习 RSpec 时,我很困惑为什么会有shared_examples_for
和share_as
。
我倾向于使用share_as
作为顶级组:
describe Model do
include MySharedSpecs
context 'it works' do
it_should_behave_like 'a working model'
我切换到shared_examples_for
,一切都很好。 谢谢。
对于跳到底部的任何人,我想指出 justinko 对上述问题提供了完全令人满意的答案。
您可以通过 rspec spec/my_spec_that_contains_the_shared_group.rb --example "hello world" 在共享组中运行单个示例
最有用的评论
您可以通过
rspec spec/my_spec_that_contains_the_shared_group.rb --example "hello world"
在共享组中运行单个示例