Avatar Edgar Gonzalez

  • Random
  • Archive
  • RSS

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

    • #ruby
    • #rspec
  • 10 months ago
  • 1
  • Comments
  • Permalink
  • Share
    Tweet

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

    • #rails
    • #rails3
    • #fixtures
    • #factory_girl
    • #generators
    • #RSpec
    • #test
  • 2 years ago
  • 7
  • Comments
  • Permalink
  • Share
    Tweet

A very nice RSpec formatter

Fuubar is an RSpec formatter that uses a progress bar instead of a string of letters and dots

    • #bdd
    • #formatter
    • #rails3
    • #rspec
    • #fuubar
  • 2 years ago
  • 16
  • Comments
  • Permalink
  • Share
    Tweet

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'
    • #rails3
    • #rails
    • #rspec
    • #MongoDB
    • #mongo
    • #mongoid
    • #test
    • #bdd
    • #nosql
    • #gemfile
  • 2 years ago
  • 2
  • Comments
  • Permalink
  • Share
    Tweet

Portrait/Logo

About

Edgar Gonzalez

Father, husband, and software developer. I'm building web applications since 1994 for a living and I love it.

Rubyist, Rails developer since 2006, believer of Agile Development and Lean startups, NoSQL enthusiast.

Born in Caracas - Venezuela, living in New York.

Me, Elsewhere

  • @edgar on Twitter
  • Facebook Profile
  • edgargonzaleznetve on Youtube
  • egg on Flickr
  • edgar on Foursquare
  • Google
  • My Skype Info
  • Linkedin Profile
  • edgar on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr