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



18192 questions
10 answers

When to use RSpec let()?

I tend to use before blocks to set instance variables. I then use those variables across my examples. I recently came upon let(). According to RSpec docs, it is used to ... to define a memoized helper method. The value will be cached across…
  • 18,635
  • 16
  • 56
  • 74
16 answers

How to run a single RSpec test?

I have the following file: /spec/controllers/groups_controller_spec.rb What command in terminal do I use to run just that spec and in what directory do I run the command? My gem file: # Test ENVIRONMENT GEMS group :development, :test do gem…
  • 108,152
  • 195
  • 629
  • 1,012
15 answers

How do you run a single test/spec file in RSpec?

I want to be able to run a single spec file's tests — for the one file I'm editing, for example. rake spec executes all the specs. My project is not a Rails project, so rake spec:doc doesn't work. Don't know if this matters, but here is my…
Jonathan Tran
  • 15,214
  • 9
  • 60
  • 67
6 answers

Rspec: "array.should == another_array" but without concern for order

I often want to compare arrays and make sure that they contain the same elements, in any order. Is there a concise way to do this in RSpec? Here are methods that aren't acceptable: #to_set For example: expect(array.to_set).to eq…
  • 19,211
  • 12
  • 66
  • 82
17 answers

Rails: Missing host to link to! Please provide :host parameter or set default_url_options[:host]

I have been googling for about 90 minutes now and still don't have an answer to this. Where do I set default_url_options? I've already set it for config.action_mailer.default_url_options to solve this same bug elsewhere, but now I'm getting this…
  • 34,788
  • 19
  • 120
  • 195
8 answers

iOS Tests/Specs TDD/BDD and Integration & Acceptance Testing

What are the best technologies to use for behavior-driven development on the iPhone? And what are some open source example projects that demonstrate sound use of these technologies? Here are some options I've found: Unit Testing Test::Unit…
  • 121,420
  • 116
  • 450
  • 651
5 answers

How to use RSpec's should_raise with any kind of exception?

I'd like to do something like this: some_method.should_raise How should I do this? some_method.should_raise exception ... doesn't work.
  • 65,020
  • 52
  • 178
  • 231
10 answers

How do I run only specific tests in Rspec?

I think there's a way to run only tests with a given label. Anybody know?
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
14 answers

Testing modules in RSpec

What are the best practices on testing modules in RSpec? I have some modules that get included in few models and for now I simply have duplicate tests for each model (with few differences). Is there a way to DRY it up?
  • 2,768
  • 3
  • 18
  • 13
6 answers

How can I check that a form field is prefilled correctly using capybara?

I have a field with a proper label that I can fill in with capybara without a problem: fill_in 'Your name', with: 'John' I'd like to check the value it has before filling it in and can't figure it out. If I add after the fill_in the following…
Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
5 answers

How can I tell Rails to use RSpec instead of test-unit when creating a new Rails app?

I have test-unit installed and rspec installed (along with -core, -expectations, -mocks and -rails version 2.6.x). When I run the command rails new foo, it uses test-unit to generate the test stub files instead of rspec. Is there an option where I…
  • 35,986
  • 41
  • 138
  • 186
14 answers

How to check for a JSON response using RSpec?

I have the following code in my controller: format.json { render :json => { :flashcard => @flashcard, :lesson => @lesson, :success => true } In my RSpec controller test I want to verify that a certain scenario does…
  • 3,427
  • 4
  • 27
  • 43
4 answers

Set up RSpec to test a gem (not Rails)

It is pretty easy with the added generator of rspec-rails to set up RSpec for testing a Rails application. But how about adding RSpec for testing a gem in development? I am not using jeweler or such tools. I just used Bundler (bundle gem my_gem) to…
  • 16,045
  • 21
  • 90
  • 134
6 answers

How do I globally configure RSpec to keep the '--color' and '--format specdoc' options turned on

How do I set global configuration for RSpec in Ubuntu. Specifically so, --color and --format specdoc stay turned on, across all my projects (ie every time I run rspec anywhere).
  • 8,939
  • 12
  • 51
  • 63
8 answers

Trouble comparing time with RSpec

I am using Ruby on Rails 4 and the rspec-rails gem 2.14. For a my object I would like to compare the current time with the updated_at object attribute after a controller action run, but I am in trouble since the spec does not pass. That is, given…
  • 18,291
  • 27
  • 103
  • 170
2 3
99 100