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
26
votes
3 answers

Rspec validate uniqueness with scope

I have this in my Line model validates :home_team, :uniqueness => { :scope => [:visiting_team, :event_datetime], :message => "** DOUBLE EVENT **" } I have this in my spec describe Line do it { should…
slindsey3000
  • 4,053
  • 5
  • 36
  • 56
25
votes
3 answers

uninitialized constant Rspec

I created a new rails application and followed the installation instructions for rspec-rails here - https://github.com/rspec/rspec-rails I then created (copied from the interwebs) the following module in my app/lib directory. require…
geoff swartz
  • 5,437
  • 11
  • 51
  • 75
24
votes
2 answers

ActionController::UrlGenerationError, No route matches

I've read through every similar question I could find and still can't figure out my problem. # routes.rb Rails.application.routes.draw do resources :lists, only: [:index, :show, :create, :update, :destroy] do resources :items, except: [:new] …
RobertJoseph
  • 7,968
  • 12
  • 68
  • 113
24
votes
5 answers

How to include a support file for rspec

I'm building a rails 4 app. I created a support file to simulate a login. Here are the files spec/support/spec_test_helper.rb module SpecTestHelper def login(user) request.session[:user_id] = user.id end def current_user …
Ricbermo
  • 815
  • 1
  • 6
  • 28
24
votes
3 answers

ActionMailer sending real emails in test mode! - How to turn off?

Newly signed up users to my little app must be approved by the admin (me) before they can gain access to the site. I've succeeded in generating such emails in development with an after_create :send_admin_email in my user model which works great. …
BenU
  • 2,287
  • 1
  • 22
  • 35
23
votes
3 answers

How to test attr_accessible fields in RSpec

So we have been setting up attr_accessible and attr_protected on many fields through out our Rails 3.2 app. For now we really don't test to ensure that these fields are protected. So I decided to google some answers and stumbled upon this…
WarmWaffles
  • 531
  • 5
  • 16
23
votes
3 answers

undefined method `create' in Rails RSpec

I have installed FactoryBot and trying to use it with RSpec. scenario 'User signs in' do create :user, email: 'test@example.com', password: 'testpassword' visit '/users/sign_in' fill_in 'Email', with: 'test@example.com' fill_in 'Password',…
user3814030
  • 1,263
  • 3
  • 20
  • 37
23
votes
2 answers

Writing tests for a sidekiq worker

I am using the rspec-sidekiq gem (https://github.com/philostler/rspec-sidekiq) to help test a worker I am writing, but for some reason my test keeps failing. Here is my Test: require 'spec_helper' describe CommunicationWorker do it { should…
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
22
votes
2 answers

devise and rspec-rails - How to sign-in user in Request type specs (specs tagged with type: :request)?

Environment Rails 4.2.0 ruby-2.2.1 [ x86_64 ] devise 3.4.1 rspec-core 3.2.2 rspec-rails 3.2.1 In my /spec/rails_helper.rb I have included Devise helpers for spec files tagged with type: :controller and type:…
Jignesh Gohel
  • 6,236
  • 6
  • 53
  • 89
22
votes
3 answers

DatabaseCleaner + RSpec : what is the correct configuration?

I included database_cleaner gem in my rails app. Followed the example given on the git repo and included the following code in spec_helper : Approach 1 config.before(:suite) do DatabaseCleaner.strategy = :transaction …
Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
21
votes
2 answers

Rails: Shoulda-matchers belong_to optional test

I have a model class Certificate < ApplicationRecord notification_object belongs_to :user belongs_to :share_class, optional: true belongs_to :round, optional: true belongs_to :company, optional: true has_many :approvals, as:…
meerkat
  • 361
  • 1
  • 3
  • 11
21
votes
1 answer

create method in Rspec

I need to understand this line of code in Rspec. create(:practice, creator: create(:physician, password: "password123", password_confirmation: "password123" ), phone: "+1 (555) 555-5554", office: "+1 (555) 555-5555", clinic_key: "abc123") What is…
Adnan Ali
  • 2,890
  • 5
  • 29
  • 50
20
votes
5 answers

Test for HTTP status code in some RSpec rails request exampes, but for raised exception in others

In a Rails 4.2.0 application tested with rspec-rails, I provide a JSON web API with a REST-like resource with a mandatory attribute mand_attr. I'd like to test that this API answers with HTTP code 400 (BAD REQUEST) when that attribute is missing…
das-g
  • 9,718
  • 4
  • 38
  • 80
20
votes
3 answers

Sending custom headers through RSpec

Given my API consumers are required to send a customer HTTP header like this: # curl -H 'X-SomeHeader: 123' http://127.0.0.1:3000/api/api_call.json Then I can read this header in a before_filter method like this: #…
Sebastian Roth
  • 11,344
  • 14
  • 61
  • 110
20
votes
3 answers

Capybara 2.1 Error uninitialized constant Rails (NameError)

I just upgraded my Capybara Gem from version 1 to 2.1.0 (latest). Based on Capybara Readme, I added this following lines to my spec_helper.rb inside Spork.prefork block require 'capybara/rspec' require 'capybara/rails' But, I got an…
Glend Maatita
  • 623
  • 7
  • 14