Questions tagged [rspec2]

RSpec 2 is a version of the Behaviour-Driven Development tool for Ruby programmers. Use this tag only for RSpec 2-specific questions, and tag those questions with [rspec] too.

RSpec 2 is a version of the Behaviour-Driven Development tool for Ruby programmers.

As with all tags with version numbers, please use this tag only for questions which are actually specific to RSpec 2, and always tag such questions with the non-versioned tag as well as with this tag.

1156 questions
20
votes
6 answers

How to test routes in a Rails 3.1 mountable engine

I am trying to write some routing specs for a mountable rails 3.1 engine. I have working model and controller specs, but I cannot figure out how to specify routes. For a sample engine, 'testy', every approach I try ends with the same error: …
Cameron Pope
  • 7,565
  • 2
  • 26
  • 24
20
votes
2 answers

Skip an RSpec test case at runtime

I'm running RSpec tests against a website product that exists in several different markets. Each market has subtly different combinations of features, etc. I would like to be able to write tests such that they skip themselves at runtime depending on…
andrewdotnich
  • 16,195
  • 7
  • 38
  • 57
20
votes
8 answers

rspec-email - How to get the body text?

I'm using rspec with the email-spec gem. I'm trying to do: last_delivery = ActionMailer::Base.deliveries.last last_delivery.body.should include "This is the text of the email" But that doesn't work, is there a way to say body, text version?…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
20
votes
2 answers

Rspec Controller testing with Javascript

How do you test a controller in Rspec if the controller only responds with javascript? For example this would be my actual code: some view.html.erb link_to 'More Chips', add_chips_path, :remote => true chips_controller def add_chips …
hoitomt
  • 670
  • 1
  • 6
  • 16
20
votes
1 answer

RoR: testing an action that uses http token authentication

I'm trying to test a controller that's using an http token authentication in the before filter. My problem is that it works ok wheh I use curl to pass the token, but in my tests it always fails (I'm using rspec btw). Tried a simple test to see if…
JoseMarmolejos
  • 1,760
  • 1
  • 17
  • 34
19
votes
5 answers

How to test after_sign_in_path_for(resource)?

I have devise authentication and registration set up on my Rails app. I'm using after_sign_in_path_for() to customise the redirect when the user signs in based on various scenarios. What I'm asking is how to test this method? It seems hard to…
David Tuite
  • 22,258
  • 25
  • 106
  • 176
19
votes
2 answers

rspec test result from csv.read mocking file

I'm using ruby 1.9 and I'm trying to do BDD. My first test 'should read in the csv' works, but the second where I require a file object to be mocked doesn't. Here is my model spec: require 'spec_helper' describe Person do describe "Importing…
map7
  • 5,096
  • 6
  • 65
  • 128
19
votes
1 answer

Rails / RSpec: How to test #initialize method?

How can I specify #initialize behaviour with RSpec? For example here: generator.rb class Generator attr_accessor :seed def initialize(seed = nil) @seed = seed || pick_seed end def pick_seed Time.now.to_i …
avsej
  • 3,822
  • 4
  • 26
  • 31
18
votes
3 answers

How can I access metadata in rspec before(:all)?

I would like to be able to display a test group name (and ancestry) during the before(:all) method: describe "My awesome app" do before(:all) do puts running_example_group.metadata[:full_description] # <- what I'm imagining ... done …
Ben Flynn
  • 18,524
  • 20
  • 97
  • 142
18
votes
3 answers

Factory Girl: How to associate a record to another record without creating a new record?

I'm using Factory Girl/Rspec2/Rails 3. In factories.rb, I have: Factory.define :user do |user| user.name 'Some guy' user.email 'some_guy@somewhere.org' user.password 'password' end Factory.define :org_admin, :parent => :user do…
Sean Lerner
  • 389
  • 5
  • 9
18
votes
5 answers

Rails 3 RSpec 2 NetBeans integration

NetBeans 6.9 provides a custom Runner class for RSpec to be integrated into the IDE. I'm trying to get my Rails 3 applications specs to be correctly displayed inside NetBeans, but RSpec 2 seems no longer to support custom Runner classes in…
aef
  • 4,498
  • 7
  • 26
  • 44
18
votes
8 answers

Proper way to wait for a second page to load with Capybara when the first has the same field as the second

I'm having a problem with a spec that visits two forms with the same field ("Email") on both forms. If I don't manually sleep, Capybara seems to be finding the "Email" field from the first visit in the second portion of the test. # visit the first…
Alex
  • 4,122
  • 5
  • 34
  • 40
17
votes
2 answers

How to test routes with Rspec 2 in Rails 3?

I can't find anything explaining how to test routes in Rails 3. Even in the Rspec book, it doesn't explain well. Thanks
donald
  • 23,587
  • 42
  • 142
  • 223
17
votes
2 answers

How to test scopes?

tried to find but with no success. Just wondering how could I test scopes in Rails 3. Could be using rspec, shoulda or just a test unit. Thanks. Actually, I trying this way, but it's not complete test since it's still need to put the order()…
Kleber S.
  • 8,110
  • 6
  • 43
  • 69
17
votes
3 answers

Does an RSpec2 matcher for matching Hashes exist?

Note to future readers: think RSpec does not consider your Hashes equal? One might be an OrderedHash, but from the regular RSpec output you can't tell. This was the problem that prompted this post. Original question: Suppose I have a spec where I…
Confusion
  • 16,256
  • 8
  • 46
  • 71