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
58
votes
4 answers

RSpec: Is there a not for `and change`, e.g. `and_not to change`?

I find the .and method very useful for chaining many expectations. expect { click_button 'Update Boilerplate' @boilerplate_original.reload } .to change { @boilerplate_original.title }.to('A new boilerplate') .and change {…
Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152
58
votes
2 answers

RSpec any_instance deprecation: how to fix it?

In my Rails project I'm using rspec-mocks using any_instance but I want to avoid this deprecation message: Using any_instance from rspec-mocks' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or…
Rowandish
  • 2,655
  • 3
  • 31
  • 52
58
votes
1 answer

RSpec: specifying multiple calls to a method with different argument each time

In rspec (1.2.9), what is the correct way to specify that an object will receive multiple calls to a method with a different argument each time? I ask because of this confusing result: describe Object do it "passes, as expected" do foo =…
Wayne Conrad
  • 103,207
  • 26
  • 155
  • 191
58
votes
2 answers

In RSpec, what's the difference between before(:suite) and before(:all)?

The before and after hook documentation on Relish only shows that before(:suite) is called prior to before(:all). When should I use one over the other?
Mark Rushakoff
  • 249,864
  • 45
  • 407
  • 398
57
votes
6 answers

With RSpec, how to seed the database on load?

I'm using rspec for testing w my rails 3 app. I need to seed the database before the tests start. How can I seed the database with the following: /db/seeds.rb ["Admin", "Member"].each do |role_name| …
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
57
votes
5 answers

How do I simulate a login with RSpec?

I have been playing with Rails for a couple of years now and have produced a couple of passable apps that are in production. I've always avoided doing any testing though and I have decided to rectify that. I'm trying to write some tests for an app…
brad
  • 9,573
  • 12
  • 62
  • 89
56
votes
4 answers

How to emulate mouse hover with Capybara

Basically, what I'm trying to do is click on a button that becomes visible when hovering another element (its parent). I have tried to use trigger.('mouseover') on the parent of the hidden button, but that doesn't seem to work. Here's a code snippet…
adritha84
  • 957
  • 1
  • 7
  • 15
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
54
votes
6 answers

Visit method not found in my rspec

My java web application is running on tomcat at http://localhost:8080/ Writing my first spec, home_spec: require 'spec_helper' describe "home" do it "should render the home page" do visit "/" page.should have_content("hello…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
54
votes
20 answers

Rails : RuntimeError - can't modify frozen Array when running rspec in rails

I recently upgraded to Rails 5.1 from v4.3 and am now getting this error when running tests: An error occurred while loading ./spec/controllers/admin/capacity_charges_controller_spec.rb. Failure/Error: require…
jeznag
  • 4,183
  • 7
  • 35
  • 53
54
votes
3 answers

Running a spec in RubyMine results in "cannot load such file -- teamcity/spec/runner/formatter/teamcity/formatter (LoadError)"

OS: Arch Linux, Rails version: 4, RubyMine: 6.3 When I run a spec from Tools - Run Rake Task - spec I always get this error: /home/chylli/.rvm/gems/ruby-2.1.2@rails4/gems/rspec-core-3.0.2/lib/rspec/core/configuration.rb:1024:in `require': cannot…
chylli
  • 561
  • 1
  • 4
  • 7
54
votes
9 answers

How can I validate exits and aborts in RSpec?

I am trying to spec behaviors for command line arguments my script receives to ensure that all validation passes. Some of my command line arguments will result in abort or exit being invoked because the parameters supplied are missing or…
cfeduke
  • 23,100
  • 10
  • 61
  • 65
53
votes
3 answers

How to set private instance variable used within a method test?

Given a class with a couple of instance variables and some methods. Some instance variables are set accessible via attr_reader and attr_accessor. Thus the others are private. Some of the private instance variables get set within one of the instance…
Torbjörn
  • 5,512
  • 7
  • 46
  • 73
53
votes
2 answers

How to load a spec_helper.rb automatically in RSpec 2

When developing gems in Ruby, I almost always need a file in which I can configure RSpec to my needs and maybe before doing that, require some helper modules which should be available in all my spec examples. In Rails applications a file named…
aef
  • 4,498
  • 7
  • 26
  • 44
53
votes
5 answers

Is it impossible to use Guard with RubyMine?

For some inexplicable reason, RubyMine autosaves every change you make and so every key stroke will trigger Guard to run your tests! And the most ridiculous thing is that there's apparently no way to disable this autosaving "feature". I'm just…
yiinewbie
  • 1,055
  • 2
  • 12
  • 19