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
156
votes
6 answers

test a file upload using rspec - rails

I want to test a file upload in rails, but am not sure how to do this. Here is the controller code: def uploadLicense #Create the license object @license = License.create(params[:license]) #Get Session ID sessid =…
user727403
  • 1,967
  • 3
  • 13
  • 14
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
119
votes
1 answer

RSpec: What is the difference between a feature and a request spec?

What is the conceptual difference between Rspec's feature specs and request specs? From the feature spec docs: Feature specs are high-level tests meant to exercise slices of functionality through an application. They should drive the application…
harm
  • 10,045
  • 10
  • 36
  • 41
117
votes
5 answers

How do I turn on SQL debug logging for ActiveRecord in RSpec tests?

I have some RSpec tests for my models and I would like to turn on SQL ActiveRecord logging just like I see in the Rails server mode. How to do that? I start my tests with RAILS_ENV=test bundle exec rspec my/test_spec.rb Thanks
lzap
  • 16,417
  • 12
  • 71
  • 108
100
votes
2 answers

How is spec/rails_helper.rb different from spec/spec_helper.rb? Do I need it?

I am doing the Rails Tutorial for the second time. When I enter this rails generate integration_test static_pages I get spec/rails_helper.rb and spec/spec_helper.rb instead of just spec/spec_helper.rb Now when I run my tests, they are longer (more…
user3417583
  • 1,417
  • 3
  • 11
  • 13
97
votes
12 answers

Factory-girl create that bypasses my model validation

I am using Factory Girl to create two instances in my model/unit test for a Group. I am testing the model to check that a call to .current returns only the 'current' groups according to the expiry attribute as per below... describe ".current" do …
Norto23
  • 2,249
  • 3
  • 23
  • 40
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
76
votes
12 answers

Unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)

While testing scenario by cucumber i'm getting the following error when running rspec tests unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError) Using ruby (1.9.2)…
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
71
votes
7 answers

Rails 5, Rspec: Environment data not found in the schema

After upgrading a Rails app to Rails 5, running RSpec tests gives me the following error: rails aborted! ActiveRecord::NoEnvironmentInSchemaError: Environment data not found in the schema. To resolve this issue, run: bin/rails…
steel
  • 11,883
  • 7
  • 72
  • 109
70
votes
1 answer

Controller spec unknown keyword: id

I have simple action show def show @field = Field.find_by(params[:id]) end and i want write spec for it require 'spec_helper' RSpec.describe FieldsController, type: :controller do let(:field) { create(:field) } it 'should show field'…
user
  • 1,341
  • 2
  • 17
  • 28
61
votes
7 answers

rails-rspec error cannot load such file -- rspec/core/formatters/progress_formatter

I've broken my rails-rspec. I switched to a different gemset to run a 3rd party test. When I returned to my 2.3.0(default) gemset, I had the following errors. running rspec…
Sawyer Merchant
  • 1,243
  • 2
  • 12
  • 21
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
52
votes
3 answers

Why is my RSpec not loading Devise::Test::ControllerHelpers?

I'm using Rails 5, and Devise 3.5.1. Going through a nice (older) book about creating/testing an API, which uses Devise authentication. It was written before Rails 5, so I chose not to use the new api-only version. Here's my…
dwilbank
  • 2,470
  • 2
  • 26
  • 37
49
votes
2 answers

expected true to respond to true?

I upgraded my rspec-rails to 3.0.1 and now I'm seeing this error on all of my tests Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true expected true to respond to `true?` I can't find the solution nor what I'm missing.
Luiz E.
  • 6,769
  • 10
  • 58
  • 98
1
2 3
99 100