LoginSignup
3
3

More than 5 years have passed since last update.

Running Rspec

Last updated at Posted at 2013-12-17

Resource: Rspec slide

Running rspec

$ rspec 

Output options

-f, --format FORMATTER  [p]rogress | [d]ocumentation | [h]tml
-o, --out FILE
-c, --[no-]color,--[no-]colour 
-p, --[no-]profile [COUNT] # enable profiling of examples and list the slowest examples (default: 10)

Color Formatter

$ rspec --color spec/
# add it in .rspec file

Documentation

$ rspec -f doc spec/

html

$ rspec -f html # or h

Progress

$ rspec -f p # or progress

Fuubar

Fuubar

Fuubar is an instafailing RSpec formatter that uses a progress bar instead of a string of letters and dots as feedback.

Installation:

gem install ruby-progressbar

or in your Gemfile

gem 'ruby-progressbar'

Then, when running rspec:

rspec --format Fuubar --color spec

Or, if you want to use Fuubar as your default formatter, simply put the options in your .rspec file:

--format Fuubar
--color

Multiple formatters

$ rspec -f Fuubar -f html -o specs.html spec/

Profiling

$ rspec --profile spec/
# or
$ rspec -p spec/

Pending specs

The followingss will output with Pending notes.

Example 1

describe "Something" do
  it "does something" do
    ...
  end

 it "does something I haven't implemented yet"
end

Example 2

describe "Something" do
  ...

  it "does something I haven't implemented yet" do
    pending "waiting for inspiration"
    ...
  end
end

Example 3

describe "Something" do
  before { pending "Coming soon!" }

  it "does something" do
  end

  it "does something else" do
  end
end

Running one spec

Line number 5.

$ rspec -f doc spec/something_spec.rb:5

Filtering

Filtering by tag

describe "Something" do
  it "does stuff" do
    ...
  end

  it "does the thing I'm working on", :current => true do
    ...
  end
end

Run only specs tagged ‘current’

rspec --tag current ...

Run specs not tagged ‘current’

rspec --tag ~current ...

Filtering by tag value

describe "Something" do
  it "behaves one way in Ruby 1.8", :ruby => "1.8" do
    ...
  end

  it "behaves another way in Ruby 1.9", :ruby => "1.9" do
    ...
  end
end

Run 1.8 specs:

rspec --tag ruby:1.8

Implicit filtering

RUBY_1_9 = (RUBY_VERSION =~ /^1\.9/)

describe "Something" do
  it "does this when using 1.9", :if => RUBY_1_9 do
    ...
  end

  it "Does that when not using 1.9", :unless => RUBY_1_9 do
    ...
  end
end

Filtering by name

describe "Something" do
  it "does stuff" do ...

  it "does other stuff" do ...

  it "does one more thing" do ...
end

Select specs using a regular expression:

$ rspec -e stuff spec/something_spec.rb
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3