RSpec Fixtures

Gem Travis Maintainability Issues Gemnasium


RSpec Fixtures allows you to interactively review and approve testable content.

asciicast


Install

$ gem install rspec_fixtures

Or with bundler:

gem 'rspec_fixtures'

Usage

Require the gem in your spec helper:

# spec/spec_helper.rb
require 'rspec_fixtures'

And use any of the matchers in your specs.

describe 'ls' do
  it "works" do
    expect(`ls`).to match_fixture('ls_fixture')
  end
end

Matchers

match_fixture

Compare a string with a pre-approved fixture.

expect('some string').to match_fixture('fixture_filename')

output_fixture

Compare an output (stdout or stderr) with a pre-approved fixture.

expect{ puts "hello" }.to output_fixture('fixture_filename')
expect{ puts "hello" }.to output_fixture('fixture_filename').to_stdout
expect{ $stderr.puts "hello" }.to output_fixture('fixture_filename').to_stderr

# The first two are the same, as the default stream is stdout.

Configuration

interactive_fixtures

By default, interactive approvals are enabled in any environment that does not define the CI environment variable. You can change this by adding this to your spec_helper

RSpec.configure do |config|
  config.interactive_fixtures = false # or any logic
end

fixtures_path

By default, fixtures are stored in spec/fixtures. To change the path, add this to your spec_helper.

RSpec.configure do |config|
  config.fixtures_path = 'spec/anywhere/else'
end