Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Mongoid::FixtureSet with RSpec #6

Open
PandaWhisperer opened this issue Oct 17, 2016 · 6 comments
Open

Using Mongoid::FixtureSet with RSpec #6

PandaWhisperer opened this issue Oct 17, 2016 · 6 comments

Comments

@PandaWhisperer
Copy link

I want to use this gem with RSpec, but can't quite figure out how. So far, I have this in my spec_helper.rb:

require 'mongoid-fixture_set'

RSpec.configure do |config|
  config.include Mongoid::FixtureSet::TestHelper
end

I'm not really sure how to set the fixture_path, however.

@Aethelflaed
Copy link
Owner

Have you tried config.fixture_path ?

@PandaWhisperer
Copy link
Author

@Aethelflaed I haven't. Just tried it and it gives me the following error:

undefined method `fixture_path=' for #<RSpec::Core::Configuration:0x007f91bc8370e8> (NoMethodError)

@PandaWhisperer
Copy link
Author

PandaWhisperer commented Oct 20, 2016

Aha. It seems to work when I use this instead:

require 'mongoid-fixture_set'

RSpec.configure do |config|
  config.include Mongoid::FixtureSet::TestHelper
  config.add_setting(:fixture_path, default: "#{Rails.root}/spec/fixtures")
end

However, that still doesn't make the fixtures available. I either need to call setup_fixtures myself, or add this to the configuration:

  config.before(:each) { setup_fixtures }
  config.after(:each) { teardown_fixtures }

@PandaWhisperer
Copy link
Author

PandaWhisperer commented Oct 20, 2016

After managing to get Mongoid::FixtureSet set up with RSpec as above, when running my tests, RSpec gets stuck for an extremely long time (30+ seconds) on the loading fixtures step, even though I've only defined a single, very minimal fixture file, spec/fixtures/currencies.yml:

usd:
  label: US Dollar
  code: USD
  status: active
  created_by: 2
  updated_by: 2

euro:
  label: Euro
  code: EUR
  status: active
  created_by: 2
  updated_by: 2

After the long wait, it eventually fails with the following error:

TypeError:
    no implicit conversion of nil into String
# ~/.rvm/gems/ruby-2.2.4/gems/mongoid-fixture_set-1.5.0/lib/mongoid/fixture_set.rb:69:in `join'
# ~/.rvm/gems/ruby-2.2.4/gems/mongoid-fixture_set-1.5.0/lib/mongoid/fixture_set.rb:69:in `block in create_fixtures'
# ~/.rvm/gems/ruby-2.2.4/gems/mongoid-fixture_set-1.5.0/lib/mongoid/fixture_set.rb:64:in `map'
# ~/.rvm/gems/ruby-2.2.4/gems/mongoid-fixture_set-1.5.0/lib/mongoid/fixture_set.rb:64:in `create_fixtures'
# ~/.rvm/gems/ruby-2.2.4/gems/mongoid-fixture_set-1.5.0/lib/mongoid/fixture_set/test_helper.rb:91:in `load_fixtures'
# ~/.rvm/gems/ruby-2.2.4/gems/mongoid-fixture_set-1.5.0/lib/mongoid/fixture_set/test_helper.rb:75:in `setup_fixtures'
# ./spec/routes/categories_spec.rb:41:in `block (2 levels) in <top (required)>'

@PandaWhisperer
Copy link
Author

PandaWhisperer commented Oct 20, 2016

Turns setting fixture_path using config.add_setting was actually not setting the fixture path correctly so that Mongoid::FixtureSet could find it. Therefore, the test helper ends up scanning the entire file system for .yml files.

This works:

RSpec.configure do |config|
  config.before(:all) do
    self.class.fixture_path = "#{Rails.root}/spec/fixtures"
  end
end

@Aethelflaed
Copy link
Owner

glad you found a way to work around it, need any other help?
Sorry for late reply, I took a holiday and wasn't much connected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants