Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 61 lines (51 sloc) 1.519 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
Feature: match unless raises

In order, primarily, to reuse existing test/unit assertions
As an RSpec user
I want to define matchers that wrap a statement that raises an error on failure

Background:
Given a file named "example.rb" with:
"""
require 'test/unit/assertions'

Spec::Matchers.define :be_the_same_as do |expected|
extend Test::Unit::Assertions
match_unless_raises Test::Unit::AssertionFailedError do |actual|
assert_equal expected, actual
end
end
"""
Scenario: passing examples
Given a file named "match_unless_raises_spec.rb" with:
"""
require './example.rb'

describe 4 do
it "is 4" do
4.should be_the_same_as(4)
end
end

describe 5 do
it "is not 4" do
5.should_not be_the_same_as(4)
end
end
"""
When I run "spec match_unless_raises_spec.rb"
Then the stdout should include "2 examples, 0 failures"

Scenario: failing examples
Given a file named "match_unless_raises_spec.rb" with:
"""
require './example.rb'

describe 4 do
it "is 4" do
# intentionally fail
4.should_not be_the_same_as(4)
end
end

describe 5 do
it "is not 4" do
# intentionally fail
5.should be_the_same_as(4)
end
end
"""
When I run "spec match_unless_raises_spec.rb"
Then the stdout should include "2 examples, 2 failures"
Something went wrong with that request. Please try again.