Questions tagged [rspec-rails]

rspec-rails is an extension of the RSpec testing framework that provides support for testing Ruby on Rails applications.

About:

RSpec began life in 2005 as an experiment by Steven Baker, with early contributions from Dave Astels and Aslak Hellesøy. David Chelimsky joined the team that summer, and accepted leadership of the project in 2006. David also built rspec-rails, which provided tight integration with Ruby on Rails.

RSpec 1.0 was released in May of 2007, and included many of the features that are still present in RSpec today. RSpec 1's runner had many great features but had reached a point where it was slow and hard to continue evolving it.

In late 2008, Chad Humphries built Micronaut, a new spec runner, to address these problems. Micronaut also included a new metadata system that provided much greater flexibility than RSpec 1 had.

In early 2010, after the release of RSpec 1.3, David and Chad began working on RSpec 2. The project got split into separate, modular pieces that could be used individually or all together. Micronaut was used as the basis of rspec-core, the new runner. RSpec 2 was released in October 2010 after nearly a year of effort.

In November 2012, after leading the project for 6 years, David decided to move on to other things. He asked Myron Marston to take over as lead RSpec maintainer and Andy Lindeman to take over as lead rspec-rails maintainer.

Work on RSpec 3 began in July 2013 and it was released in June 2014. RSpec 3 was a bit of a "spring cleaning" for RSpec, removing much cruft (some of which dated back to RSpec 1!). It also provided verifying doubles, composable matchers, a new syntax that allows RSpec to be used with no monkey patching, and many other new features. Andy Lindeman retired from the team and asked Aaron Kromer to take over as rspec-rails maintainer.

Today, RSpec continues to improve and evolve thanks to the input of a large community and the work of hundreds of contributors.

Links:

2442 questions
46
votes
7 answers

POSTing raw JSON data with Rails 3.2.11 and RSpec

In order to ensure that my application is not vulnerable to this exploit, I am trying to create a controller test in RSpec to cover it. In order to do so, I need to be able to post raw JSON, but I haven't seemed to find a way to do that. In doing…
Daniel Vandersluis
  • 91,582
  • 23
  • 169
  • 153
45
votes
4 answers

How can I test :inclusion validation in Rails using RSpec

I have the following validation in my ActiveRecord. validates :active, :inclusion => {:in => ['Y', 'N']} I am using the following to test my model validations. should_not allow_value('A').for(:active) should allow_value('Y').for(:active) should…
jake
  • 2,371
  • 1
  • 20
  • 31
45
votes
3 answers

How do I get an ENV variable set for rspec?

I'm using foreman to start up my rails development server. It's nice that I can put all of my environment variables in the .env file. Is there a way to do something similar for my test environment? I want to set an API key that I will use with the…
Cyrus
  • 3,687
  • 5
  • 35
  • 67
43
votes
4 answers

Capybara tests with :js=>true... Routing Error: No route matches [GET] "/assets"

I'm getting a similar error in a number of tests when I add ":js => true" to them. eg: An error occurred in an after hook ActionController::RoutingError: No route matches [GET] "/assets" occurred at…
Reb
  • 649
  • 1
  • 8
  • 12
41
votes
2 answers

Rails 3.1 plugin gem, dummy test app, rspec

So Rails 3.1 comes with a little-known handy "rails g plugin new" generator, which gives you a skeleton suitable for a rails gem plugin. [http://guides.rubyonrails.org/plugins.html#or-generate-a-gemified-plugin] One of the useful things this does,…
jrochkind
  • 22,799
  • 12
  • 59
  • 74
41
votes
1 answer

Rspec/Capybara loading in progress, circular require considered harmful

Unsure if this is a Capybara issue, but I just did a fresh install of Rails (4.1.1) and Rspec Rails (3.0.1) and I would like to use Capybara (2.3.0), but having never used it I'm running into issues. I created a "spec" in spec/features and the spec…
typeoneerror
  • 55,990
  • 32
  • 132
  • 223
37
votes
2 answers

Testing Rails 3.1 mountable engine with Rspec

I started making a Rails 3.1 engine, and I'm having a hard time testing it using rspec. First of all, if I run rails g integration_test whatever it creates a regular integration test in tests/integration instead of spec/requests (the rspec-rails gem…
deb
  • 12,326
  • 21
  • 67
  • 86
36
votes
1 answer

Show runtime for each rspec example

currently I'm running more than 1k examples and it's taking a long time to complete (more than 20 minutes!!!). I'd like to identify which examples are the ones taking more time to complete, is there any way to run rspec and return the time each…
jpemberthy
  • 7,473
  • 8
  • 44
  • 52
36
votes
3 answers

mock Rails.env.development? using rspec

I am writing a unit test using rspec. I would like to mock Rails.env.develepment? to return true. How could I achieve this?. I tried this Rails.env.stub(:development?, nil).and_return(true) it throws this…
ssinganamalla
  • 1,250
  • 3
  • 12
  • 19
34
votes
4 answers

Accessing controller instance variables from within an rspec controller spec

Shouldn't I be able to see instance variables which are created in a controller action from within my rspect tests? # /app/controllers/widget_controller.rb ... def show @widget = ... puts "in controller: #{@widget}" end ... -- #…
RobertJoseph
  • 7,968
  • 12
  • 68
  • 113
32
votes
4 answers

How to include lib directory in rspec tests

I am having a problem in testing my gem which includes a lib directory, on JRuby 1.7.4. I want to test a file located at lib/vger/resources/account_manager.rb My spec file is in spec/vger/resources/account_manager_spec.rb require…
Akash Khandelwal
  • 346
  • 1
  • 4
  • 10
31
votes
6 answers

How to complete the rspec put controller test from scaffold

I'm using scaffolding to generate rspec controller tests. By default, it creates the test as: let(:valid_attributes) { skip("Add a hash of attributes valid for your model") } describe "PUT update" do describe "with valid params" do …
Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
29
votes
6 answers

Unable to stub helper method with rspec

I am trying to stub a method on a helper that is defined in my controller. For example: class ApplicationController < ActionController::Base def current_user @current_user ||= authenticated_user_method end helper_method…
Brad
  • 5,428
  • 1
  • 33
  • 56
28
votes
4 answers

How to examine rspec variables with pry debugger

I've seen some SO posts explaining how to use pry to step into rspec tests and been able to do this. Once I reach the breakpoint though, I'm struggling to display any useful information. For this code below, I'd like to examine the response object…
PropertyWebBuilder
  • 1,286
  • 2
  • 12
  • 18
26
votes
1 answer

How to set a value in the params hash when testing a Rails helper method with RSpec?

In Ruby on Rails 4, with RSpec 3.1, how do I set the values of the params hash when testing a Rails helper method? I want to set params[:search] = 'my keyword search' for use in my helper method and then call it from within the it example…
sealocal
  • 10,897
  • 3
  • 37
  • 50