riot 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -115,6 +115,13 @@ Sometimes, your test raises an exception that you actually expected.
115
115
  asserts("invalid data") { @user.save! }.raises(ActiveRecord::RecordInvalid)
116
116
  end
117
117
 
118
+ And if you wanted to check that the exception and message match what you expect:
119
+
120
+ context "a new user" do
121
+ setup { @user = User.new }
122
+ asserts("invalid data") { @user.save! }.raises(ActiveRecord::RecordInvalid, /has errors/)
123
+ end
124
+
118
125
  #### Example: Kind Of
119
126
 
120
127
  When you want to test that an expression returns an object of an expected type:
@@ -23,7 +23,7 @@ module Riot
23
23
  private
24
24
  def actualize(situation, &block)
25
25
  @actual = situation.instance_eval(&block)
26
- @default_failure = fail("expected true, not #{@actual.inspect}") unless @actual
26
+ @default_failure = fail("expected true, not #{@actual.inspect}") unless @actual == true
27
27
  rescue Exception => e
28
28
  @raised = e
29
29
  end
data/lib/riot/macros.rb CHANGED
@@ -17,10 +17,17 @@ module Riot
17
17
  # Asserts that the test raises the expected Exception
18
18
  # asserts("test") { raise My::Exception }.raises(My::Exception)
19
19
  # should("test") { raise My::Exception }.raises(My::Exception)
20
- def raises(expected)
21
- fail("should have raised #{expected}, but raised nothing") unless raised
22
- fail("should have raised #{expected}, not #{error.class}") unless expected == raised.class
20
+ # asserts("test") { raise My::Exception, "Foo" }.raises(My::Exception, "Foo")
21
+ # asserts("test") { raise My::Exception, "Foo Bar" }.raises(My::Exception, /Bar/)
22
+ def raises(expected, expected_message=nil)
23
+ actual_error = raised
23
24
  @raised = nil
25
+ return fail("should have raised #{expected}, but raised nothing") unless actual_error
26
+ return fail("should have raised #{expected}, not #{error.class}") unless expected == actual_error.class
27
+ if expected_message && !(actual_error.message =~ %r[#{expected_message}])
28
+ return fail("expected #{expected_message} for message, not #{actual_error.message}")
29
+ end
30
+ true
24
31
  end
25
32
 
26
33
  # Asserts that the result of the test equals matches against the proved expression
data/riot.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "riot"
3
- s.version = "0.9.0"
3
+ s.version = "0.9.1"
4
4
  s.date = "2009-10-03"
5
5
  s.summary = "An extremely fast, expressive, and context-driven unit-testing framework"
6
6
  s.email = %w[gus@gusg.us]
@@ -39,6 +39,30 @@ end # nil assertion
39
39
 
40
40
  context "raises assertion:" do
41
41
  should("raise an Exception") { raise Exception }.raises(Exception)
42
+
43
+ should "pass if provided message equals expectation" do
44
+ Riot::Assertion.new("foo", fake_context) do
45
+ raise Exception, "I'm a nerd"
46
+ end.raises(Exception, "I'm a nerd")
47
+ end.equals(true)
48
+
49
+ should "fail if provided message does not equal expectation" do
50
+ Riot::Assertion.new("foo", fake_context) do
51
+ raise(Exception, "I'm a nerd")
52
+ end.raises(Exception, "But I'm not")
53
+ end.kind_of(Riot::Failure)
54
+
55
+ should "pass if provided message matches expectation" do
56
+ Riot::Assertion.new("foo", fake_context) do
57
+ raise(Exception, "I'm a nerd")
58
+ end.raises(Exception, %r[nerd])
59
+ end.equals(true)
60
+
61
+ should "fail if provided message does not match expectation" do
62
+ Riot::Assertion.new("foo", fake_context) do
63
+ raise(Exception, "I'm a nerd")
64
+ end.raises(Exception, %r[foo])
65
+ end.kind_of(Riot::Failure)
42
66
  end # raises assertion
43
67
 
44
68
  context "matching assertion:" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Knowlden