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

How can I tell Rails to use RSpec instead of test-unit when creating a new Rails app?

I have test-unit installed and rspec installed (along with -core, -expectations, -mocks and -rails version 2.6.x). When I run the command rails new foo, it uses test-unit to generate the test stub files instead of rspec. Is there an option where I…
aarona
  • 35,986
  • 41
  • 138
  • 186
161
votes
4 answers

Set up RSpec to test a gem (not Rails)

It is pretty easy with the added generator of rspec-rails to set up RSpec for testing a Rails application. But how about adding RSpec for testing a gem in development? I am not using jeweler or such tools. I just used Bundler (bundle gem my_gem) to…
medihack
  • 16,045
  • 21
  • 90
  • 134
127
votes
3 answers

RSpec: describe, context, feature, scenario?

describe, context, feature, scenario: What is the difference(s) among the four and when do I use each one?
Mike Glaz
  • 5,352
  • 8
  • 46
  • 73
100
votes
6 answers

How to get rspec-2 to give the full trace associated with a test failure?

Right now if I run my test suite using rake spec I get an error: 1) SegmentsController GET 'index' should work Failure/Error: get 'index' undefined method `locale' for # # ./spec/controllers/segments_controller_spec.rb:14: in `block…
marcgg
  • 65,020
  • 52
  • 178
  • 231
96
votes
6 answers

How do I prepare test database(s) for Rails rspec tests without running rake spec?

After significant troubleshooting, I figured out that I needed to run rake spec once (I can abort with control-c) before I can run rspec directly (e.g. on a subset of our specs). We are running Rails 3.0.7 and RSpec 2.5.0. Clearly, rake is running…
gerry3
  • 21,420
  • 9
  • 66
  • 74
78
votes
2 answers

Object.any_instance should_receive vs expect() to receive

The following piece of code works as expected: Object.any_instance.should_receive(:subscribe) But when using the new rspec expectation it does not work: expect(Object.any_instance).to receive(:subscribe) The error is: expected: 1 time with any…
Calin
  • 6,661
  • 7
  • 49
  • 80
73
votes
7 answers

Rails 3.1, RSpec: testing model validations

I have started my journey with TDD in Rails and have run into a small issue regarding tests for model validations that I can't seem to find a solution to. Let's say I have a User model, class User < ActiveRecord::Base validates :username,…
Feech
  • 4,072
  • 4
  • 28
  • 36
65
votes
6 answers

Rspec testing redirect_to :back

How do you test redirect_to :back in rspec? I get ActionController::RedirectBackError: No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify…
Cyrus
  • 3,687
  • 5
  • 35
  • 67
62
votes
2 answers

RSpec documentation...where is it hiding?

Having a terrible time finding RSpec-2 (and rspec-rails) documentation. Specifically I want to look up all available Matchers... but how? I've tried: RSpec.info : outdated - RSpec 1.x rdoc.info : seems useless, to me anyway.…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
58
votes
2 answers

In RSpec, what's the difference between before(:suite) and before(:all)?

The before and after hook documentation on Relish only shows that before(:suite) is called prior to before(:all). When should I use one over the other?
Mark Rushakoff
  • 249,864
  • 45
  • 407
  • 398
56
votes
1 answer

before hook in rspec same as before :all?

I am wondering whether the before (as seen below) is the same as before :all in RSpec. Sometimes neither :each nor :all is specified and it confuses me as to what before actually does. require 'spec_helper' describe "this is a description" do …
Jonathan Lin
  • 19,922
  • 7
  • 69
  • 65
53
votes
2 answers

How to load a spec_helper.rb automatically in RSpec 2

When developing gems in Ruby, I almost always need a file in which I can configure RSpec to my needs and maybe before doing that, require some helper modules which should be available in all my spec examples. In Rails applications a file named…
aef
  • 4,498
  • 7
  • 26
  • 44
50
votes
2 answers

Testing STDOUT output in Rspec

I am trying to build a spec for this statement. It is easy with 'puts' print "'#{@file}' doesn't exist: Create Empty File (y/n)?"
user2292710
  • 511
  • 1
  • 4
  • 3
49
votes
3 answers

How to include Rails Helpers on RSpec

I'm trying to include some helpers to test with rspec but no luck. What I did: created a support/helpers.rb file under my spec folder. support/helpers.rb module Helpers include ActionView::Helpers::NumberHelper include…
Kleber S.
  • 8,110
  • 6
  • 43
  • 69
49
votes
8 answers

How to test with RSpec if an email is delivered

I'd like to test if an email is delivered if I call a controller method with :post. I'll use email_spec so I tried this snipped here: http://rubydoc.info/gems/email_spec/1.2.1/file/README.rdoc#Testing_In_Isolation But it doesn't work, because I pass…
fossil12
  • 497
  • 1
  • 4
  • 9
1
2 3
77 78