hydra
hydra copied to clipboard
Shared rspec example groups not loading
Hey there, I'm having an issue with hydra with rspec where shared examples aren't able to be used for some reason (shared_examples_for).
It's able to load my environment and successfully run tests, but when it comes to one that uses shared examples defined in another file that was loaded on startup, it errors out.
I created a demo project that has the full stacktrace of the error that you should be able to reproduce: RAILS_ENV=test rake hydra https://github.com/adamfortuna/hydra-rspec-failure-demo
Here's a briefer overview: In spec_helper.rb we load up some rspec shared examples:
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
require(file)
end
shared_examples_for "a demo example" do
it "doesnt error out" do
true.should == true
end
end
Then attempt to use these later on in a test:
require 'spec_helper'
describe ApplicationHelper do
it_should_behave_like "a demo example"
end
Which results in this error:
1303850302.11934 RUNNER| Running file: spec/helpers/application_helper_spec.rb 1303850302.18619 RUNNER| Could not find shared example group named "a demo example" /Users/adam/.rvm/gems/ree-1.8.7-2010.02/gems/rspec-core-2.0.0.beta.19/lib/rspec/core/example_group.rb:65:in `it_should_behave_like': Could not find shared example group named "a demo example" (RuntimeError)
Full dump, gem versions and the rest in the repo, but it might just be a setup error on my part. I've tried this with various different rspec/hydra gem versions, but right now the demo is running 'hydra', '0.23.0' and 'rspec', '2.0.0.beta.19'. This spec can be run by itself, but errors out when run form hydra. Any ideas?
Hey, I had this problem on a previous project, but sadly I don't have access to that code anymore. The gist of my solution was that I had to require all the shared examples in my spec helper, and I had to check to see if they had already been defined, because sometimes they would be defined multiple times :-O
Hope that helps.
Hmm interesting, that wouldn't be too bad if it's only in the spec_helper. Right now I have it loading all the shared examples without checking to see if they've been previously defined, but don't see them. Do you remember if there was a different way they have to be loaded rather than just requiring them like this?
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
require(file)
end
Thanks!
Yeah, you can use load instead of require, which forces the code to run. Then you need to check if they're defined or it will complain. On Apr 26, 2011 6:33 PM, "adamfortuna" < [email protected]> wrote:
Hmm interesting, that wouldn't be too bad if it's only in the spec_helper. Right now I have it loading all the shared examples without checking to see if they've been previously defined, but don't see them. Do you remember if there was a different way they have to be loaded rather than just requiring them like this?
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file| require(file) endThanks!
Reply to this email directly or view it on GitHub: https://github.com/ngauthier/hydra/issues/39#comment_1061253
In brief testing, commenting out this line in Hydra and recompiling the gem seems to do the trick. Not sure if it's affecting something else just yet though. Could you provide a bit of background on what this line is doing? Any shared_examples_for blocks that are set will be reset once this line runs.
RSpec.instance_variable_set(:@world, nil)
That wipes the world so that it must reinstantiate itself between runs. Otherwise, the same specs run multiple times. The side effect is that it wipes the shared examples as well.
If you're just doing local parallelization, maybe the parallel_tests gem is worth a look? On Apr 26, 2011 7:58 PM, "adamfortuna" < [email protected]> wrote:
In brief testing, commenting out this line in Hydra and recompiling the gem seems to do the trick. Not sure if it's affecting something else just yet though. Could you provide a bit of background on what this line is doing? Any shared_examples_for blocks that are set will be reset once this line runs.
RSpec.instance_variable_set(:@world, nil)Reply to this email directly or view it on GitHub: https://github.com/ngauthier/hydra/issues/39#comment_1061610