Questions tagged [rspec]

RSpec is a behavior-driven development (BDD) framework for the Ruby programming language, inspired by JBehave. It contains its own fully integrated mocking framework based upon JMock. The framework can be considered a domain-specific language (DSL) and resembles a natural language specification.

RSpec is a behaviour-driven development (BDD) tool for Ruby programmers. BDD is an approach to software development that combines test-driven development (TDD), domain-driven design (DDD), and acceptance test-driven planning (ATDP). RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.

RSpec 2 and later site

RSpec 1 site

Resources

Books

18192 questions
53
votes
11 answers

Set Rspec default GET request format to JSON

I am doing functional tests for my controllers with Rspec. I have set my default response format in my router to JSON, so every request without a suffix will return JSON. Now in rspec, i get an error (406) when i try get :index I need to do get…
Drazen
  • 2,776
  • 1
  • 25
  • 39
52
votes
3 answers

Does rspec have anything more specific than target.should be < 6?

http://cheat.errtheblog.com/s/rspec/ has for inequalities (such as less than or greater than) target.should be < 6 Has anything better been created since the cheat sheet was created?
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
52
votes
3 answers

How to use RSpec without Rails?

What is the process for doing TDD in Ruby with RSpec without Rails? Do I need a Gemfile? Does it only need rspec in it? Ruby 1.9.3
B Seven
  • 44,484
  • 66
  • 240
  • 385
51
votes
2 answers

Rspec stubbing method for only specific arguments

Is there a way to stub method for only specific arguments. Something like this boss.stub(:fire!).with(employee1).and_return(true) If any other employee is passed to boss.fire! method, I'll get boss received unexpected message error, but what I…
Milovan Zogovic
  • 1,541
  • 2
  • 16
  • 24
51
votes
7 answers

How to test rendering a partial with RSpec

I want to test rendering a particular partial according to some conditions. For example, in model show action view show.html.erb I have: <% if condition1 %> <%= render :partial => "partial1" %> <% else %> <%= render :partial => "partial1" %> <%…
Pavel
  • 3,900
  • 6
  • 32
  • 41
51
votes
3 answers

How to force an RSpec test to fail?

What's the proper way to force an RSpec test to fail? I'm considering 1.should == 2 however there's probably something better.
SundayMonday
  • 19,147
  • 29
  • 100
  • 154
51
votes
4 answers

Selenium::WebDriver::Error::JavascriptError: waiting for evaluate.js load failed Firefox 23

Today running my rspec tests, I get the following error whenever somewhere in a test theres a `page.execute_script' call. Selenium::WebDriver::Error::JavascriptError: waiting for evaluate.js load failed # [remote server]…
Hsiu Dai
  • 1,303
  • 2
  • 14
  • 21
51
votes
2 answers

Is there a way to unstub in RSpec?

Searched the Relish docs, but did not find a way to unstub in RSpec. Is this possible?
B Seven
  • 44,484
  • 66
  • 240
  • 385
51
votes
9 answers

Suppress console output during RSpec tests

I am testing the class which put on the console some messages (with puts, p warnings and etc.). I am just wondering if there is any ability to suppress this output during RSpec tests ?
ceth
  • 44,198
  • 62
  • 180
  • 289
51
votes
3 answers

In RSpec, is there a method equivalent to "unstub" but for "should_receive"?

Is there any method to remove any stubbing and mocking while using RSpec? Example: RestClient.should_receive(:delete).with("http://www.example.com") ... ... # this will remove the mocking of "should_receive" and # restore the proper "delete"…
p.matsinopoulos
  • 7,655
  • 6
  • 44
  • 92
50
votes
3 answers

Controller Specs vs Request Specs?

I'm working on a rails API and I'm now planning on writing some RSpec tests for the controllers. I've been reading around and I haven't been able to figure out what the actual difference between controller specs and request specs are and which one…
jsanch16
  • 609
  • 1
  • 8
  • 9
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
50
votes
4 answers

Correct way of testing "associations" with Rspec?

I am trying to test the following scenario: -> I have a model called Team which it just makes sense when it has been created by a User. Therefore, each Team instance has to be related to a User. In order to test that, I have done the…
Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
50
votes
2 answers

Minitest and Rspec

I have just watched a Railscast for Minitest. What are the pros and cons for using RSpec vs Minitest for testing a rails app? Which features will I lose converting from RSpec to Minitest?
GTDev
  • 5,488
  • 9
  • 49
  • 84
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