riot 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +35 -16
- data/lib/riot/macros.rb +7 -0
- data/riot.gemspec +2 -1
- data/test/assertion_macros/assertion_macro_respond_to_test.rb +16 -0
- metadata +2 -1
data/README.markdown
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
An extremely fast, expressive, and context-driven unit-testing framework. Protest the slow test.
|
4
4
|
|
5
|
+
#### Installation
|
6
|
+
|
7
|
+
The Riot gem is hosted on gemcutter.org. It used to be hosted on GitHub, but they turned of gem support while moving to Rackspace, so we moved to gemcutter. If you have not already done so, add gemcutter.org to your list of gem sources like so:
|
8
|
+
|
9
|
+
sudo gem sources -a http://gemcutter.org
|
10
|
+
|
11
|
+
Then, simply install the Riot gem like so:
|
12
|
+
|
13
|
+
sudo gem install riot
|
14
|
+
|
5
15
|
### Note on speed
|
6
16
|
|
7
17
|
I have done a really simple benchmarking (10,000 runs), but right now, Riot is running about **2 times** faster than Test::unit and thusly Shoulda:
|
@@ -34,8 +44,8 @@ For instance, given a test file named `foo_test.rb`, you might have the followin
|
|
34
44
|
require 'riot'
|
35
45
|
|
36
46
|
context "a new user" do
|
37
|
-
setup {
|
38
|
-
asserts("that it is not yet created") {
|
47
|
+
setup { User.new }
|
48
|
+
asserts("that it is not yet created") { topic.new_record? }
|
39
49
|
end
|
40
50
|
|
41
51
|
Notice that you do not define a class anywhere. That would be the entire contents of that test file. If you wanted to use a `should` instead, you could say this:
|
@@ -43,8 +53,8 @@ Notice that you do not define a class anywhere. That would be the entire content
|
|
43
53
|
require 'riot'
|
44
54
|
|
45
55
|
context "a new user" do
|
46
|
-
setup {
|
47
|
-
should("not be created") {
|
56
|
+
setup { User.new }
|
57
|
+
should("not be created") { topic.new_record? }
|
48
58
|
end
|
49
59
|
|
50
60
|
Sometimes it's more clear to say "this **should** be that" and sometimes it's better to say "**asserts** this is that". I promise you that Riot will get no more redundant than this, but also that besides speed, Riot will aim at being expressive with a minimal amount of syntax.
|
@@ -58,8 +68,8 @@ One of the most common assertions you will (or do already) utilize is that of eq
|
|
58
68
|
For example:
|
59
69
|
|
60
70
|
context "a new user" do
|
61
|
-
setup {
|
62
|
-
asserts("email address") {
|
71
|
+
setup { User.new(:email => 'foo@bar.com') }
|
72
|
+
asserts("email address") { topic.email }.equals('foo@bar.com')
|
63
73
|
end
|
64
74
|
|
65
75
|
Here, you should begin to notice that tests themselves return the actual value. You do not write assertions into the test. Assertions are "aspected" onto the test. If the test above did not return 'foo@bar.com' for `@user.email`, the assertion would have failed.
|
@@ -67,8 +77,8 @@ Here, you should begin to notice that tests themselves return the actual value.
|
|
67
77
|
The `equals` modifier works with any type of value, including nil's. However, if you wanted to test for nil explicitly, you could simply do this:
|
68
78
|
|
69
79
|
context "a new user" do
|
70
|
-
setup {
|
71
|
-
asserts("email address") {
|
80
|
+
setup { User.new }
|
81
|
+
asserts("email address") { topic.email }.nil
|
72
82
|
end
|
73
83
|
|
74
84
|
Notice the `nil` modifier added to asserts. Also notice how the test almost reads as "a new user asserts email address *is* nil". With Test::Unit, you would have probably written:
|
@@ -100,10 +110,10 @@ In my opinion, the same redundancy exists. Sure, I could write a macro like `sho
|
|
100
110
|
If you need to assert that a test result matches a regular expression, use the `matches` modifier like so:
|
101
111
|
|
102
112
|
context "a new user" do
|
103
|
-
setup {
|
113
|
+
setup { User.new }
|
104
114
|
|
105
115
|
# I'm a contrived example
|
106
|
-
asserts("random phone number") {
|
116
|
+
asserts("random phone number") { topic.random_phone_number }.matches(/^\d{3}-\d{3}-\d{4}$/)
|
107
117
|
end
|
108
118
|
|
109
119
|
#### Example: Raises
|
@@ -111,15 +121,15 @@ If you need to assert that a test result matches a regular expression, use the `
|
|
111
121
|
Sometimes, your test raises an exception that you actually expected.
|
112
122
|
|
113
123
|
context "a new user" do
|
114
|
-
setup {
|
115
|
-
asserts("invalid data") {
|
124
|
+
setup { User.new }
|
125
|
+
asserts("invalid data") { topic.save! }.raises(ActiveRecord::RecordInvalid)
|
116
126
|
end
|
117
127
|
|
118
128
|
And if you wanted to check that the exception and message match what you expect:
|
119
129
|
|
120
130
|
context "a new user" do
|
121
|
-
setup {
|
122
|
-
asserts("invalid data") {
|
131
|
+
setup { User.new }
|
132
|
+
asserts("invalid data") { topic.save! }.raises(ActiveRecord::RecordInvalid, /has errors/)
|
123
133
|
end
|
124
134
|
|
125
135
|
#### Example: Kind Of
|
@@ -127,8 +137,17 @@ And if you wanted to check that the exception and message match what you expect:
|
|
127
137
|
When you want to test that an expression returns an object of an expected type:
|
128
138
|
|
129
139
|
context "a new user" do
|
130
|
-
setup {
|
131
|
-
asserts("its balance") {
|
140
|
+
setup { User.new }
|
141
|
+
asserts("its balance") { topic.balance }.kind_of(Currency)
|
142
|
+
end
|
143
|
+
|
144
|
+
#### Example: Respond To
|
145
|
+
|
146
|
+
When you want to test that an object responds to a specific method:
|
147
|
+
|
148
|
+
context "a new user" do
|
149
|
+
setup { User.new }
|
150
|
+
asserts("email is defined") { topic }.respond_to(:email)
|
132
151
|
end
|
133
152
|
|
134
153
|
#### Example: Assigns
|
data/lib/riot/macros.rb
CHANGED
@@ -59,6 +59,13 @@ module Riot
|
|
59
59
|
actual.kind_of?(expected) || fail("expected kind of #{expected}, not #{actual.inspect}")
|
60
60
|
end
|
61
61
|
|
62
|
+
# Asserts that the result of the test is an object that responds to the given method
|
63
|
+
# asserts("test") { "foo" }.respond_to(:to_s)
|
64
|
+
# should("test") { "foo" }.respond_to(:to_s)
|
65
|
+
def respond_to(expected)
|
66
|
+
actual.respond_to?(expected) || fail("expected method #{expected.inspect} is not defined")
|
67
|
+
end
|
68
|
+
|
62
69
|
# Asserts that an instance variable is defined for the result of the assertion. Value of instance
|
63
70
|
# variable is expected to not be nil
|
64
71
|
# setup { User.new(:email => "foo@bar.baz") }
|
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.
|
3
|
+
s.version = "0.9.7"
|
4
4
|
s.date = "2009-10-07"
|
5
5
|
s.summary = "An extremely fast, expressive, and context-driven unit-testing framework"
|
6
6
|
s.email = %w[gus@gusg.us]
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
test/assertion_macros/assertion_macro_matching_test.rb
|
34
34
|
test/assertion_macros/assertion_macro_nil_test.rb
|
35
35
|
test/assertion_macros/assertion_macro_raises_test.rb
|
36
|
+
test/assertion_macros/assertion_macro_respond_to_test.rb
|
36
37
|
test/assertion_test.rb
|
37
38
|
test/benchmark/simple_context_and_assertions.rb
|
38
39
|
test/context_test.rb
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "respond to" do
|
4
|
+
setup do
|
5
|
+
Riot::Situation.new
|
6
|
+
end
|
7
|
+
|
8
|
+
should "pass when object responds to expected method" do
|
9
|
+
Riot::Assertion.new("foo", topic) { "foo" }.respond_to(:each_byte)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "fail when object does not respond to expected method" do
|
13
|
+
Riot::Assertion.new("foo", topic) { "foo" }.respond_to(:goofballs).message
|
14
|
+
end.equals("foo: expected method :goofballs is not defined")
|
15
|
+
|
16
|
+
end # respond to
|
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.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Knowlden
|
@@ -69,6 +69,7 @@ test_files:
|
|
69
69
|
- test/assertion_macros/assertion_macro_matching_test.rb
|
70
70
|
- test/assertion_macros/assertion_macro_nil_test.rb
|
71
71
|
- test/assertion_macros/assertion_macro_raises_test.rb
|
72
|
+
- test/assertion_macros/assertion_macro_respond_to_test.rb
|
72
73
|
- test/assertion_test.rb
|
73
74
|
- test/benchmark/simple_context_and_assertions.rb
|
74
75
|
- test/context_test.rb
|