ruby-on-rails 等级库文件加载顺序问题:在'find_and_eval_shared'中:找不到共享示例

djmepvbi  于 2022-12-01  发布在  Ruby
关注(0)|答案(2)|浏览(80)

我目前正在研究 Rails 4 Test Prescriptions,遇到了一个本书中没有提到的规范文件的加载顺序问题。不幸的是,我无法从我所能找到的问题中解决这个问题。当我尝试运行我的测试时,得到的输出是

/Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:370:in `find_and_eval_shared': Could not find shared examples "sizeable" (ArgumentError)
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:310:in `block (2 levels) in define_nested_shared_group_method'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:385:in `module_exec'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:385:in `subclass'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:258:in `block in define_example_group_method'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:309:in `block in define_nested_shared_group_method'
    from /Users/Admin/Desktop/Apps/gatherer/spec/models/task_spec.rb:4:in `block in <top (required)>'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:385:in `module_exec'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:385:in `subclass'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:258:in `block in define_example_group_method'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/dsl.rb:43:in `block in expose_example_group_alias'
    from /Users/Admin/Desktop/Apps/gatherer/spec/models/task_spec.rb:3:in `<top (required)>'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `block in load_spec_files'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `each'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1433:in `load_spec_files'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:100:in `setup'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:86:in `run'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:71:in `run'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/runner.rb:45:in `invoke'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/exe/rspec:4:in `<top (required)>'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `load'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/bin/rspec:23:in `<main>'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/Admin/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'

您可以在https://github.com/jamesemcc/gatherer上查看我的存储库
谢谢你的帮助!

yr9zkbsy

yr9zkbsy1#

将共享示例声明文件size_group.rb加载到您的task_spec.rb
就像这样:

require 'support/size_group'

编辑:
最好将shared_example主示例加载到rails_helper.rb中。

3lxsmp7m

3lxsmp7m2#

有一个类似的问题“找不到共享的示例...”
在我的情况下,解决方案是:
我在组名上打错了

describe 'my_string', :my_string do
    it_behaves_like 'a name with a typo', GraphQL::Types::String
  end

相关问题