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
66
votes
2 answers

how to test params passed into a controller in rails 3, using rspec?

Our code: describe "GET show" do it "assigns the requested subcategory as @subcategory" do subcategory = Subcategory.create! valid_attributes get :show, :id => subcategory.id.to_s assigns(:subcategory).should eq(subcategory) …
lkahtz
  • 4,706
  • 8
  • 46
  • 72
66
votes
4 answers

Rails/Rspec - testing a redirect in the controller

So I am currently writing a test for a controller in an existing controller that just didn't have one before. What I want to test is a redirect that happens when someone is not allowed to edit something vs someone that is allowed to edit it. the…
legendary_rob
  • 12,792
  • 11
  • 56
  • 102
65
votes
6 answers

Rspec testing redirect_to :back

How do you test redirect_to :back in rspec? I get ActionController::RedirectBackError: No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify…
Cyrus
  • 3,687
  • 5
  • 35
  • 67
65
votes
3 answers

RSpec: How could I use the array include matcher in the expect syntax

I use new RSpec syntax (expect instead of should) and I'd like to test if an array includes elements of another array. In the old syntax it would be: array1.should include(array2) In the new syntax I tried to write: expect(array1).to…
mrzasa
  • 22,895
  • 11
  • 56
  • 94
65
votes
4 answers

How to fill hidden field with Capybara?

I've already found that when I want to set value to text field, text area or password field, I can use id, name or label as something in fill_in something, :with => some_value. However such approach fails when I try to set value to
skalee
  • 12,331
  • 6
  • 55
  • 57
64
votes
3 answers

Clearing out ActionMailer::Base.deliveries after RSpec test

I have the following RSpec test for my UserMailer class: require "spec_helper" describe UserMailer do it "should send welcome emails" do ActionMailer::Base.deliveries.should be_empty user = Factory(:user) …
Kevin Pang
  • 41,172
  • 38
  • 121
  • 173
62
votes
2 answers

RSpec documentation...where is it hiding?

Having a terrible time finding RSpec-2 (and rspec-rails) documentation. Specifically I want to look up all available Matchers... but how? I've tried: RSpec.info : outdated - RSpec 1.x rdoc.info : seems useless, to me anyway.…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
62
votes
12 answers

Could not find generator rspec:install (q2)

I'm trying to follow this tutorial here: http://railstutorial.org/chapters/static-pages#top When I run: $ rails generate rspec:install I get: Could not find generator rspec:install. What could be the problem? [Rails 3, 4, 5, 6, 7] Thanks.
Simplicity
  • 47,404
  • 98
  • 256
  • 385
62
votes
4 answers

Rails rspec set subdomain

I am using rSpec for testing my application. In my application controller I have a method like so: def set_current_account @current_account ||= Account.find_by_subdomain(request.subdomains.first) end Is it possible to set the request.subdomain…
RailsSon
  • 19,897
  • 31
  • 82
  • 105
61
votes
4 answers

How to spec a private method

I got a model with a private method I'd like to spec with RSpec, how do you usually do ? Do you only test the method calling the private one ? or also spec the private one ? if so, how do you do ?
Mike
  • 5,165
  • 6
  • 35
  • 50
61
votes
4 answers

How do you test an AJAX request with RSpec/RoR?

I'm fairly new to RoR and recently started learning BDD/Rspec for testing my application. I've been looking for a way to spec an AJAX request, but so far I haven't found much documentation on this at all. Anyone know how to do this? I'm using…
user480826
  • 611
  • 1
  • 5
  • 3
61
votes
2 answers

Guard with RSpec on Rails 4 giving a lot of warnings

I'm wondering how I can turn off all these warnings when running a simple test: [1] guard(main)> 16:59:46 - INFO - Run all 16:59:46 - INFO - Running all specs /Users/esjd/.rvm/gems/ruby-2.1.2/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:124:…
foobar
  • 10,854
  • 18
  • 58
  • 66
61
votes
3 answers

What's the difference between "include_examples" and "it_behaves_like"?

In RSpec, what's the difference between it_behaves_like and include_examples? The documentation says: include_examples — include(s) the examples in the current context it_behaves_like "name" — include(s) the examples in a nested context But what…
GMA
  • 5,816
  • 6
  • 51
  • 80
60
votes
3 answers

Using Rspec, how do I test the JSON format of my controller in Rails 3.0.11?

I've scoured the web, but, alas, I just can't seem to get Rspec to correctly send content-type so I can test my JSON API. I'm using the RABL gem for templates, Rails 3.0.11, and Ruby 1.9.2-p180. My curl output, which works fine (should be a 401, I…
gaahrdner
  • 651
  • 1
  • 5
  • 7
58
votes
6 answers

Running Rake tasks in Rspec Tests

I am building up an integration test suite and there is one bit of logic that I need to have a clean database for. How can I run the db:test:purge task inside of one of my tests? I am using: ruby 1.9.2, rails 3.0.9, rspec 2.6
xentek
  • 2,555
  • 2
  • 20
  • 12