The annoying “warning: useless use of == in void context” in RSpec
If in your specs you have something like this:
it "should be bar" do foo.should == 'bar' something_else end
The ruby -w command will throw the following warning:
warning: useless use of == in void context
The way to avoid this is using this:
foo.should eql('bar')
Or:
foo.should be == 'bar'
Or move the statement
foo.should == 'bar'
so that it’s the last line inside the it block
Replacing fixture generation on Rails 3
Because I don’t like fixtures (I use factory_girl), I change my Rails generators to generate factories instead of fixtures
To do this, just add this to your config/application.rb:
config.generators do |g| g.test_framework :test_unit, :fixture_replacement => :factory_girl end
But in my case, because I prefer rspec instead of test_unit, I use this:
config.generators do |g| g.fixture_replacement :factory_girl, :dir => "spec/factories" end
Changing the factories directory from test/factories (default) to spec/factories.
Because I’m using the rspec-rails gem, I don’t have to define the test framework (but I can), so this works too:
config.generators do |g| g.test_framework :rspec g.fixture_replacement :factory_girl, :dir => "spec/factories" end
RSpec with Mongoid
If you are using Mongoid as ORM and RSpec for testing maybe you are interested in use the mongoid-rspec gem.
mongoid-rspec provide several RSpec matchers and macros for Mongoid.
If you are using the new master branch of Mongoid (which is my case), probably you are facing this error when try to run your specs (rake spec):
no such file to load -- mongoid/associations (LoadError)
This is because the new master branch of Mongoid has deleted the file mongoid/associations. You need use the safe_master branch. Or you can try to use this fork of Mongoid-rspec compatible with Mongoid 2.0.0.rc1:
https://github.com/shingara/mongoid-rspec/tree/mongoid-2.0.0.rc1
To do this, just add this gem to your gemfile:
gem 'mongoid-rspec', :git => 'git://github.com/shingara/mongoid-rspec.git',
:branch => 'mongoid-2.0.0.rc1'