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
74
votes
13 answers

undefined method `get' for #

Anyone know how to get around this? On OSX, trying to get RSpec running with Rails 3.0.7. Full details at: https://gist.github.com/1017044 it "renders buttons_widgets partial" do get :buttons_widgets response.should…
99miles
  • 10,942
  • 18
  • 78
  • 123
74
votes
3 answers

Testing private method in Ruby (rspec)

Yes, I know, that testing private methods it's not a good idea (and I read this thread - http://www.ruby-forum.com/topic/197346 - and some others) But how can I test the following code? I use xmpp4r. In my public method #listen I start receive…
Andrey
  • 744
  • 1
  • 5
  • 9
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
73
votes
13 answers

Error when trying to run rspec: `require': cannot load such file -- rails_helper (LoadError)

I am trying to run rspec for Ruby on Rails. I am running Rails 4.1.1. I have installed the gem, have established a spec folder with some tests. I have created a directory through $ rails g rspec:install I tried to create a testing database…
HPJAJ
  • 1,464
  • 2
  • 13
  • 18
72
votes
8 answers

Capybara: How to test the title of a page?

In a Rails 3 application using Steak, Capybara and RSpec how do I test the page's title?
Nerian
  • 15,901
  • 13
  • 66
  • 96
72
votes
11 answers

BDD and TDD for node.js?

What is used for BDD and TDD with node.js? I'm used to use Cucumber + RSpec. What's a good combo for node.js? thanks
donald
  • 23,587
  • 42
  • 142
  • 223
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
71
votes
1 answer

Shoulda/RSpec matchers - conditional validation

In my code I had the following validation with Shoulda matchers, which works fine: it { should validate_presence_of(:name) } In my model, I've added the condition to my validation: validates_presence_of :name, :if => eligible? Is it possible to…
alexs333
  • 12,143
  • 11
  • 51
  • 89
70
votes
4 answers

Testing hash contents using RSpec

I have a test like so: it "should not indicate backwards jumps if the checker position is not a king" do board = Board.new game_board = board.create_test_board board.add_checker(game_board, :red, 3, 3) x_coord = 3 y_coord = 3 …
steve_gallagher
  • 3,778
  • 8
  • 33
  • 51
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
70
votes
2 answers

Using RSpec to check if something is an instance of another object

I need a way to check if an object is an instance of another object using RSpec. For example: describe "new shirt" do it "should be an instance of a Shirt object" # How can i check if it is an instance of a shirt object end end
Dillon Benson
  • 4,280
  • 4
  • 23
  • 25
69
votes
7 answers

Get select value of dropdown for capybara testing

I have to write tests for a web site. I am trying to get the selected value of a dropdown box. So far i can get the contents of the dropdown by doing find_field('restrictions__rating_movies').text returns - Don't Allow…
Brandon
  • 1,425
  • 2
  • 16
  • 19
68
votes
1 answer

RSpec allow/expect vs just expect/and_return

In RSpec, specifically version >= 3, is there any difference between: Using allow to set up message expectations with parameters that return test doubles, and then using expect to make an assertion on the returned test doubles Just using expect to…
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
67
votes
6 answers

How to stub ApplicationController method in request spec

I am needing to stub the response of a current_user method in an Rspec/capybara request spec. The method is defined in ApplicationController and is using helper_method. The method should simply return a user id. Within the test, I'd like this method…
Matt Fordham
  • 3,147
  • 10
  • 34
  • 51
67
votes
3 answers

How to expect some (but not all) arguments with RSpec should_receive?

class Foo def bar(a, b) ... Foo.should_receive( :bar ) expects bar to be called with any arguments. Foo.should_receive( :bar ).with( :baz, :qux ) expects :baz and :qux to be passed in as the params. How to expect the first param to equal…
B Seven
  • 44,484
  • 66
  • 240
  • 385