3
votes

I have recently started using RSpec for Integration testing in my Rails application, to avoid having to keep up to date with multiple testing frameworks, and am in the process of converting my Cucumber features to RSpec.

I have successfully got 1 integration test running, however, it appears to run through the example twice:

rspec spec/integration/create_article_spec.rb -f documentation

admin creates article
  successfully creates article

admin creates article
  successfully creates article

Finished in 0.51816 seconds
2 examples, 0 failures

Here is the contents of create_article_spec.rb:

require 'spec_helper'

feature "admin creates article" do
 scenario "successfully creates article" do
  visit admin_articles_url
  click_link "New Article"
  fill_in "Title", with: "Test 1"
  fill_in "Body", with: "Test Article"
  click_button "Save"
  page.should have_content "New Article Published"
 end
end

I can't find any reason why this may be happening, and all the other situations where this has happened don't apply in my case.

It only appears to happen with my Integration tests, all other tests do not appear to be affected.

I'm hoping someone with more RSpec knowledge than I can figure out where I may be missing something.

Versions

Rails (3.2.2) RSpec (2.8.0) RSpec-rails (2.8.1)

2
anything weird in your spec_helper.rb ?Kevin Davis
Are you using spork? Also, do you have rspec-rails in your Gemfile?Jay Moorthi
Just an aside: if you're migrating from cucumber, it might be easier to switch to turnip, which runs on rspec but is similar to cucumber because it uses gherkin syntax. See github.com/jnicklas/turnip.Zubin
@KevinDavis, you were right, I had a line including all the files in my integration tests folder, so they were being loaded twice. I removed that line and it solved the issue.delphiniccoder

2 Answers

4
votes

I realised that I had a line in my spec_helper.rb file including all the files in my integration tests folder, so they were in fact being loaded twice. I removed that line and it solved my issue.

1
votes

Did you upgrade from a previous version of rspec? If so (and check even if you didn't) you may have a superfluous lib/tasks/rspec.rake script. If you do, delete that file and re-run your tests. You should then see that they only execute once.