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
14
votes
5 answers

Testing helpers in Rails 3 with Rspec 2 and Devise

My helper code looks like this (and works fine btw): module ProvidersHelper def call_to_review(provider) if user_signed_in? && review = Review.find_by_provider_id_and_user_id(provider.id, current_user.id) link_to "Edit Your Review",…
steve
  • 3,276
  • 27
  • 25
14
votes
5 answers

How to create a model with a certain id using rspec and factory girl

I use: gem 'rails', '3.2.11' gem 'rspec-rails', '2.13.2' gem 'webrat', '0.7.3' gem 'factory_girl_rails', '4.1.0' gem 'spork', '~> 0.9.0.rc' I want to test my HP where I always have a link to a certain user, so the pages controller for HP…
user929062
  • 807
  • 4
  • 12
  • 33
14
votes
2 answers

How to create test objects with nested attributes with FactoryGirl in Ruby on Rails?

I have an Invoice model that may contain a number of Items as well: class Invoice < ActiveRecord::Base attr_accessible :number, :date, :recipient, :items_attributes belongs_to :user has_many :items accepts_nested_attributes_for :items,…
Tintin81
  • 9,821
  • 20
  • 85
  • 178
14
votes
3 answers

RSpec: Flush table / destroy objects after each context

How do you delete the objects (in the database and in the memory) you created after each test AND after each context? (in a context it could make sense to build tests on each other) Is there a method to do this automatically? I have the following…
migu
  • 4,236
  • 5
  • 39
  • 60
14
votes
1 answer

What's the difference between stub_model and mock_model in RSpec?

What's the difference between stub_model and mock_model in RSpec? So far, I know that stubs are used to just prevent the real method from being called and return a predefined value, and mocks are actually expectations and require that the method is…
gerky
  • 6,267
  • 11
  • 55
  • 82
14
votes
6 answers

Passing cookies in request spec

I'm trying to pass a cookie when doing a GET request, using rspec 2 and rails 3. I've tried the following so far. get "/", {}, {"Cookie" => "uuid=10"} # cookies[:uuid] is nil request.cookies[:uuid] = 10 # request is nil @request.env["Cookie"] =…
Linus Oleander
  • 17,746
  • 15
  • 69
  • 102
14
votes
2 answers

How to assert that a class will respond_to a class method with RSpec?

Let's say I have a class definition like so: class Foo def init(val) @val = val end def self.bar :bar end def val @val end end with a spec like: describe Foo it { should respond_to(:val) } it { should respond_to(:bar)…
troutwine
  • 3,721
  • 3
  • 28
  • 62
13
votes
1 answer

capybara/selenium with rspec before :all hook

In an attempt to reduce the number of page visits with selenium, I wanted to call the visit method from a before :all hook and run all my examples with a single page load. However, when I specify before :all vs before :each, the browser opens, but…
brewster
  • 4,342
  • 6
  • 45
  • 67
13
votes
5 answers

Why does upgrading to Rails 3.2.1 cause multiple Rspec tests to fail?

All 211 specs in my test suite were passing fine...until I upgraded from rails 3.2 to rails 3.2.1. Now 197 of my specs fail with errors. Most of these error have the "wrong number of arguments (0 for 1)" error described below. Example #1: class…
croceldon
  • 4,511
  • 11
  • 57
  • 92
13
votes
1 answer

Set expectation of method call while still calling original implementation

It appears as though setting any method-call expectation with Mocha prevent the original implementation from being called. This seems to cover calling the original method with rspec. Is there a way to do this with Mocha? Or does anyone know why…
aceofspades
  • 7,568
  • 1
  • 35
  • 48
13
votes
3 answers

Assert multiple change expectations within a single lambda request

I have a test like that: lambda { post("/api/users", parameters) }.should change(User,:count).by(1) lambda { post("/api/users", parameters) }.should_not change(ActionMailer::Base, :deliveries) But I want to do it like that: lambda {…
13
votes
4 answers

Spork.prefork is loading app/models/*

I can not figure out how to get spork not to load all of my app models. Testing changes to my models is greatly slowed down as I am unable to use spork to help. This is what I get when I debug what spork is loading: - Spork Diagnosis - --…
Sean McCleary
  • 3,690
  • 4
  • 33
  • 43
13
votes
1 answer

stub_chain together with should_receive

I am trying to test if in a method calling chain one of the methods get a specific parameter. In the below code for example MyModel must receive the parameter 0 for the method offset. Unfortunately the code below does not work. It seems it is not…
medihack
  • 16,045
  • 21
  • 90
  • 134
13
votes
1 answer

Which style,lambda..should or expect..to, is preferred for testing expectations in RSpec?

I have seen both styles used widely: #1 lambda { raise "Boom" }.should raise_error and #2 expect { raise "Boom" }.to raise_error. I like expect..to more as it reads better and hides the creation of the proc. I looked at rspec code and it seems…
or9ob
  • 2,313
  • 4
  • 25
  • 45
13
votes
3 answers

Rails 3 and Rspec 2 turn off transactional fixtures for individual tests

I am in the process of upgrading my application to Rails 3. I started using Rspec 2 with Rails 3. I need to turn off transactional fixtures for some of my rspec tests. Prior I used the following code in my model specs before(:all) do …
Nicolo77
  • 1,825
  • 4
  • 24
  • 34