riot 0.10.9 → 0.10.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +46 -0
- data/README.markdown +53 -16
- data/Rakefile +8 -0
- data/VERSION +1 -1
- data/lib/riot.rb +1 -1
- data/lib/riot/assertion.rb +18 -31
- data/lib/riot/assertion_macro.rb +35 -0
- data/lib/riot/assertion_macros/any.rb +12 -0
- data/lib/riot/assertion_macros/assigns.rb +27 -0
- data/lib/riot/assertion_macros/empty.rb +13 -0
- data/lib/riot/assertion_macros/equals.rb +18 -0
- data/lib/riot/assertion_macros/exists.rb +15 -0
- data/lib/riot/assertion_macros/includes.rb +17 -0
- data/lib/riot/assertion_macros/kind_of.rb +16 -0
- data/lib/riot/assertion_macros/matches.rb +17 -0
- data/lib/riot/assertion_macros/nil.rb +12 -0
- data/lib/riot/assertion_macros/raises.rb +31 -0
- data/lib/riot/assertion_macros/respond_to.rb +16 -0
- data/lib/riot/assertion_macros/same_elements.rb +14 -0
- data/lib/riot/assertion_macros/size.rb +15 -0
- data/lib/riot/context.rb +9 -17
- data/lib/riot/reporter.rb +25 -21
- data/riot.gemspec +17 -3
- data/test/assertion_macros/any_test.rb +2 -2
- data/test/assertion_macros/equals_test.rb +4 -4
- data/test/assertion_macros/exists_test.rb +2 -2
- data/test/assertion_macros/includes_test.rb +1 -1
- data/test/assertion_macros/kind_of_test.rb +1 -1
- data/test/assertion_macros/matching_test.rb +1 -1
- data/test/assertion_macros/nil_test.rb +1 -1
- data/test/assertion_macros/raises_test.rb +3 -3
- data/test/assertion_macros/respond_to_test.rb +1 -1
- data/test/assertion_macros/size_test.rb +17 -6
- data/test/assertion_test.rb +11 -6
- data/test/context_test.rb +2 -54
- data/test/report_test.rb +7 -2
- data/test/teststrap.rb +12 -3
- metadata +17 -3
- data/lib/riot/assertion_macros.rb +0 -136
data/test/assertion_test.rb
CHANGED
@@ -6,7 +6,7 @@ context "An assertion" do
|
|
6
6
|
asserts("to_s") { topic.to_s == "foo" }
|
7
7
|
|
8
8
|
asserts(":pass is returned when evaluated") do
|
9
|
-
topic.run(Riot::Situation.new) == [:pass]
|
9
|
+
topic.run(Riot::Situation.new) == [:pass, nil]
|
10
10
|
end
|
11
11
|
end # that is passing
|
12
12
|
|
@@ -32,7 +32,7 @@ context "An assertion" do
|
|
32
32
|
end
|
33
33
|
end # that is erroring
|
34
34
|
|
35
|
-
context "with no block to provide the actual" do
|
35
|
+
context "with no block to provide the actual value" do
|
36
36
|
setup do
|
37
37
|
@situation = Riot::Situation.new
|
38
38
|
@situation.topic = "hello"
|
@@ -41,8 +41,8 @@ context "An assertion" do
|
|
41
41
|
should("uses block returning topic as default") do
|
42
42
|
topic.equals("hello")
|
43
43
|
result = topic.run(@situation)
|
44
|
-
end.equals([:pass])
|
45
|
-
end
|
44
|
+
end.equals([:pass, %Q{is equal to "hello"}])
|
45
|
+
end # with no block to provide the actual value
|
46
46
|
|
47
47
|
context "with block expectation" do
|
48
48
|
setup do
|
@@ -54,11 +54,16 @@ context "An assertion" do
|
|
54
54
|
should("use block returning topic as default") do
|
55
55
|
topic.equals { "hello" }
|
56
56
|
result = topic.run(@situation)
|
57
|
-
end.equals([:pass])
|
57
|
+
end.equals([:pass, %Q{is equal to "hello"}])
|
58
58
|
|
59
59
|
asserts("block expectation has access to the situation items") do
|
60
60
|
topic.equals { @topic }
|
61
61
|
topic.run(@situation)
|
62
|
-
end.equals([:pass])
|
62
|
+
end.equals([:pass, %Q{is equal to "hello"}])
|
63
|
+
end # with block expectation
|
64
|
+
|
65
|
+
context "with symbolic description" do
|
66
|
+
setup { "foo" }
|
67
|
+
asserts(:upcase).equals("FOO")
|
63
68
|
end
|
64
69
|
end # An assertion block
|
data/test/context_test.rb
CHANGED
@@ -24,7 +24,7 @@ context "Defining a context with multiple setups" do
|
|
24
24
|
end
|
25
25
|
@a_context.run(MockReporter.new)
|
26
26
|
end
|
27
|
-
asserts("has setups") { @a_context.setups.
|
27
|
+
asserts("has setups") { @a_context.setups.size }.equals(2)
|
28
28
|
asserts("all tests pass") { topic.passes == 1 }
|
29
29
|
end # Defining a context with multiple setups
|
30
30
|
|
@@ -86,57 +86,5 @@ context "The asserts_topic shortcut" do
|
|
86
86
|
should("return the actual topic as the result of evaling the assertion") do
|
87
87
|
(situation = Riot::Situation.new).topic = "bar"
|
88
88
|
topic.equals("bar").run(situation)
|
89
|
-
end.equals([:pass])
|
89
|
+
end.equals([:pass, %Q{is equal to "bar"}])
|
90
90
|
end # The asserts_topic shortcut
|
91
|
-
|
92
|
-
context "Setting assertion extensions" do
|
93
|
-
fake_mod_one, fake_mod_two = Module.new, Module.new
|
94
|
-
|
95
|
-
setup do
|
96
|
-
Riot::Context.new("foo") do
|
97
|
-
extend_assertions fake_mod_one, fake_mod_two
|
98
|
-
end.asserts_topic
|
99
|
-
end
|
100
|
-
|
101
|
-
should("still return an Assertion") { topic }.kind_of(Riot::Assertion)
|
102
|
-
|
103
|
-
should("have included the given assertion extension modules in the assertion") do
|
104
|
-
topic.class.included_modules.include?(fake_mod_one) && topic.class.included_modules.include?(fake_mod_two)
|
105
|
-
end
|
106
|
-
|
107
|
-
context "involving subcontexts without the subcontext extending assertions" do
|
108
|
-
assertion_one = assertion_two = nil
|
109
|
-
|
110
|
-
setup do
|
111
|
-
Riot::Context.new "bleh" do
|
112
|
-
extend_assertions Module.new
|
113
|
-
assertion_one = asserts_topic
|
114
|
-
context("foo") { assertion_two = asserts_topic }
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
should "not create separate instances of the assertion class in subcontexts" do
|
119
|
-
assertion_one && assertion_two && assertion_one.class.object_id == assertion_two.class.object_id
|
120
|
-
end
|
121
|
-
end # involving subcontexts without the subcontext extending assertions
|
122
|
-
|
123
|
-
context "involving subcontexts with the subcontext extending assertions" do
|
124
|
-
assertion_one = assertion_two = nil
|
125
|
-
|
126
|
-
setup do
|
127
|
-
Riot::Context.new "bah" do
|
128
|
-
extend_assertions Module.new
|
129
|
-
assertion_one = asserts_topic
|
130
|
-
context("meh") do
|
131
|
-
extend_assertions Module.new
|
132
|
-
assertion_two = asserts_topic
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
should "create separate instances of the assertion class in subcontexts" do
|
138
|
-
assertion_one && assertion_two && assertion_one.class.object_id != assertion_two.class.object_id
|
139
|
-
end
|
140
|
-
|
141
|
-
end # involving subcontexts with the subcontext extending assertions
|
142
|
-
end # Setting assertion extensions
|
data/test/report_test.rb
CHANGED
@@ -3,7 +3,7 @@ require 'teststrap'
|
|
3
3
|
context "A reporter" do
|
4
4
|
setup do
|
5
5
|
Class.new(Riot::Reporter) do
|
6
|
-
def pass(d) "passed(#{d})"; end
|
6
|
+
def pass(d, message) "passed(#{d}, #{message.inspect})"; end
|
7
7
|
def fail(d, message) "failed(#{d}, #{message})"; end
|
8
8
|
def error(d, e) "errored(#{d}, #{e})"; end
|
9
9
|
end.new
|
@@ -18,7 +18,7 @@ context "A reporter" do
|
|
18
18
|
|
19
19
|
asserts("description sent to #pass") do
|
20
20
|
topic.report("hi mom", [:pass])
|
21
|
-
end.equals("passed(hi mom)")
|
21
|
+
end.equals("passed(hi mom, nil)")
|
22
22
|
|
23
23
|
# fail
|
24
24
|
|
@@ -56,6 +56,11 @@ context "StoryReporter" do
|
|
56
56
|
Riot::StoryReporter.new(@out)
|
57
57
|
end
|
58
58
|
|
59
|
+
asserts("success message is stripped if nil") do
|
60
|
+
topic.pass("foo", nil)
|
61
|
+
ColorHelper.uncolored(@out.string)
|
62
|
+
end.equals(" + foo\n")
|
63
|
+
|
59
64
|
context 'reporting on an empty context' do
|
60
65
|
setup do
|
61
66
|
context = Riot::Context.new('empty context') do
|
data/test/teststrap.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)+"/../lib/")
|
2
2
|
require 'riot'
|
3
|
+
Riot.verbose
|
3
4
|
|
4
5
|
module Riot
|
5
6
|
module AssertionTestContextMacros
|
6
7
|
|
7
|
-
def assertion_test_passes(description, &block)
|
8
|
+
def assertion_test_passes(description, success_message=nil, &block)
|
8
9
|
context(description) do
|
9
10
|
setup(&block)
|
10
|
-
|
11
|
+
setup { topic.run(Riot::Situation.new) }
|
12
|
+
asserts("pass") { topic.first }.equals(:pass)
|
13
|
+
asserts("success message") { topic.last }.equals(success_message)
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
@@ -25,8 +28,14 @@ end # Riot
|
|
25
28
|
Riot::Context.instance_eval { include Riot::AssertionTestContextMacros }
|
26
29
|
|
27
30
|
class MockReporter < Riot::Reporter
|
28
|
-
def pass(description); end
|
31
|
+
def pass(description, message); end
|
29
32
|
def fail(description, message); end
|
30
33
|
def error(description, e); end
|
31
34
|
def results; end
|
32
35
|
end
|
36
|
+
|
37
|
+
class ColorHelper
|
38
|
+
require 'rubygems'
|
39
|
+
require 'term/ansicolor'
|
40
|
+
extend Term::ANSIColor
|
41
|
+
end
|
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.10.
|
4
|
+
version: 0.10.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin 'Gus' Knowlden
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-29 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,6 +32,7 @@ extra_rdoc_files:
|
|
32
32
|
- README.markdown
|
33
33
|
files:
|
34
34
|
- .gitignore
|
35
|
+
- CHANGELOG
|
35
36
|
- MIT-LICENSE
|
36
37
|
- README.markdown
|
37
38
|
- Rakefile
|
@@ -39,7 +40,20 @@ files:
|
|
39
40
|
- VERSION
|
40
41
|
- lib/riot.rb
|
41
42
|
- lib/riot/assertion.rb
|
42
|
-
- lib/riot/
|
43
|
+
- lib/riot/assertion_macro.rb
|
44
|
+
- lib/riot/assertion_macros/any.rb
|
45
|
+
- lib/riot/assertion_macros/assigns.rb
|
46
|
+
- lib/riot/assertion_macros/empty.rb
|
47
|
+
- lib/riot/assertion_macros/equals.rb
|
48
|
+
- lib/riot/assertion_macros/exists.rb
|
49
|
+
- lib/riot/assertion_macros/includes.rb
|
50
|
+
- lib/riot/assertion_macros/kind_of.rb
|
51
|
+
- lib/riot/assertion_macros/matches.rb
|
52
|
+
- lib/riot/assertion_macros/nil.rb
|
53
|
+
- lib/riot/assertion_macros/raises.rb
|
54
|
+
- lib/riot/assertion_macros/respond_to.rb
|
55
|
+
- lib/riot/assertion_macros/same_elements.rb
|
56
|
+
- lib/riot/assertion_macros/size.rb
|
43
57
|
- lib/riot/context.rb
|
44
58
|
- lib/riot/reporter.rb
|
45
59
|
- lib/riot/runnable.rb
|
@@ -1,136 +0,0 @@
|
|
1
|
-
module Riot
|
2
|
-
class Assertion
|
3
|
-
# Asserts that the result of the test equals the expected value. Using the +===+ operator to assert
|
4
|
-
# equality.
|
5
|
-
# asserts("test") { "foo" }.equals("foo")
|
6
|
-
# should("test") { "foo" }.equals("foo")
|
7
|
-
# asserts("test") { "foo" }.equals { "foo" }
|
8
|
-
assertion(:equals) do |actual, expected|
|
9
|
-
expected === actual ? pass : fail("expected #{expected.inspect}, not #{actual.inspect}")
|
10
|
-
end
|
11
|
-
|
12
|
-
# Asserts that the result of the test is nil
|
13
|
-
# asserts("test") { nil }.nil
|
14
|
-
# should("test") { nil }.nil
|
15
|
-
assertion(:nil) do |actual|
|
16
|
-
actual.nil? ? pass : fail("expected nil, not #{actual.inspect}")
|
17
|
-
end
|
18
|
-
|
19
|
-
# Asserts that the result of the test is a non-nil value. This is useful in the case where you don't want
|
20
|
-
# to translate the result of the test into a boolean value
|
21
|
-
# asserts("test") { "foo" }.exists
|
22
|
-
# should("test") { 123 }.exists
|
23
|
-
# asserts("test") { "" }.exists
|
24
|
-
# asserts("test") { nil }.exists # This would fail
|
25
|
-
assertion(:exists) do |actual|
|
26
|
-
!actual.nil? ? pass : fail("expected a non-nil value")
|
27
|
-
end
|
28
|
-
|
29
|
-
# Asserts that the result of the test is an object that is a kind of the expected type
|
30
|
-
# asserts("test") { "foo" }.kind_of(String)
|
31
|
-
# should("test") { "foo" }.kind_of(String)
|
32
|
-
assertion(:kind_of) do |actual, expected|
|
33
|
-
actual.kind_of?(expected) ? pass : fail("expected kind of #{expected}, not #{actual.class.inspect}")
|
34
|
-
end
|
35
|
-
|
36
|
-
# Asserts that an instance variable is defined for the result of the assertion. Value of instance
|
37
|
-
# variable is expected to not be nil
|
38
|
-
# setup { User.new(:email => "foo@bar.baz") }
|
39
|
-
# topic.assigns(:email)
|
40
|
-
#
|
41
|
-
# If a value is provided in addition to the variable name, the actual value of the instance variable
|
42
|
-
# must equal the expected value
|
43
|
-
# setup { User.new(:email => "foo@bar.baz") }
|
44
|
-
# topic.assigns(:email, "foo@bar.baz")
|
45
|
-
assertion(:assigns) do |actual, *expectings|
|
46
|
-
variable, expected_value = expectings
|
47
|
-
variable_name = "@#{variable}"
|
48
|
-
actual_value = actual.instance_variable_defined?(variable_name) ? actual.instance_variable_get(variable_name) : nil
|
49
|
-
if actual_value.nil?
|
50
|
-
fail("expected @#{variable} to be assigned a value")
|
51
|
-
elsif !expected_value.nil? && expected_value != actual_value
|
52
|
-
fail(%Q[expected @#{variable} to be equal to #{expected_value.inspect}, not #{actual_value.inspect}])
|
53
|
-
else
|
54
|
-
pass
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Asserts that the result of the test equals matches against the proved expression
|
59
|
-
# asserts("test") { "12345" }.matches(/\d+/)
|
60
|
-
# should("test") { "12345" }.matches(/\d+/)
|
61
|
-
assertion(:matches) do |actual, expected|
|
62
|
-
expected = %r[#{Regexp.escape(expected)}] if expected.kind_of?(String)
|
63
|
-
actual =~ expected ? pass : fail("expected #{expected.inspect} to match #{actual.inspect}")
|
64
|
-
end
|
65
|
-
|
66
|
-
# Asserts that the result of the test is an object that responds to the given method
|
67
|
-
# asserts("test") { "foo" }.respond_to(:to_s)
|
68
|
-
# should("test") { "foo" }.respond_to(:to_s)
|
69
|
-
assertion(:respond_to) do |actual, expected|
|
70
|
-
actual.respond_to?(expected) ? pass : fail("expected method #{expected.inspect} is not defined")
|
71
|
-
end
|
72
|
-
|
73
|
-
# Asserts that two arrays contain the same elements, the same number of times.
|
74
|
-
# asserts("test") { ["foo", "bar"] }.same_elements(["bar", "foo"])
|
75
|
-
# should("test") { ["foo", "bar"] }.same_elements(["bar", "foo"])
|
76
|
-
assertion(:same_elements) do |actual, expected|
|
77
|
-
require 'set'
|
78
|
-
same = (Set.new(expected) == Set.new(actual))
|
79
|
-
same ? pass : fail("expected elements #{expected.inspect} to match #{actual.inspect}")
|
80
|
-
end
|
81
|
-
|
82
|
-
# Asserts that the test raises the expected Exception
|
83
|
-
# asserts("test") { raise My::Exception }.raises(My::Exception)
|
84
|
-
# should("test") { raise My::Exception }.raises(My::Exception)
|
85
|
-
#
|
86
|
-
# You can also check to see if the provided message equals or matches your expectations. The message
|
87
|
-
# from the actual raised exception will be converted to a string before any comparison is executed.
|
88
|
-
# asserts("test") { raise My::Exception, "Foo" }.raises(My::Exception, "Foo")
|
89
|
-
# asserts("test") { raise My::Exception, "Foo Bar" }.raises(My::Exception, /Bar/)
|
90
|
-
assertion(:raises, expect_exception=true) do |actual_exception, expected_class, expected_message|
|
91
|
-
actual_message = actual_exception && actual_exception.message
|
92
|
-
if actual_exception.nil?
|
93
|
-
fail("should have raised #{expected_class}, but raised nothing")
|
94
|
-
elsif expected_class != actual_exception.class
|
95
|
-
fail("should have raised #{expected_class}, not #{actual_exception.class}")
|
96
|
-
elsif expected_message && !(actual_message.to_s =~ %r[#{expected_message}])
|
97
|
-
fail("expected #{expected_message.inspect} for message, not #{actual_message.inspect}")
|
98
|
-
else
|
99
|
-
pass
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Asserts the result is empty
|
104
|
-
# asserts("a string") { "" }.empty
|
105
|
-
# asserts("an array") { [] }.empty
|
106
|
-
# asserts("a hash") { Hash.new }.empty
|
107
|
-
assertion(:empty) do |actual|
|
108
|
-
actual.length == 0 ? pass : fail("expected #{actual.inspect} to be empty")
|
109
|
-
end
|
110
|
-
|
111
|
-
# Asserts the result has items
|
112
|
-
# asserts("an array") { [1] }.any
|
113
|
-
# asserts("a hash") { {:name => 'washington'} }.any
|
114
|
-
assertion(:any) do |actual|
|
115
|
-
actual.any? ? pass : fail("expected #{actual.inspect} to have items")
|
116
|
-
end
|
117
|
-
|
118
|
-
# Asserts that result's size is as expected. Expected size can be specified as
|
119
|
-
# a number or a range.
|
120
|
-
# asserts("a string") { 'washington' }.size(9..12)
|
121
|
-
# asserts("an array") { [1, 2, 3] }.size(3)
|
122
|
-
# asserts("a hash") { {:name => 'washington'} }.size(1)
|
123
|
-
assertion(:size) do |actual, expected|
|
124
|
-
expected === actual.size ? pass : fail("size of #{actual.inspect} expected to be #{expected} but is #{actual.size}")
|
125
|
-
end
|
126
|
-
|
127
|
-
# Asserts the result contains the expected element
|
128
|
-
# asserts("a string") { "world" }.includes('o')
|
129
|
-
# asserts("an array") { [1,2,3] }.includes(2)
|
130
|
-
# asserts("a range") { (1..15) }.includes(10)
|
131
|
-
assertion(:includes) do |actual, expected|
|
132
|
-
actual.include?(expected) ? pass : fail("expected #{actual.inspect} to include #{expected.inspect}")
|
133
|
-
end
|
134
|
-
|
135
|
-
end # Assertion
|
136
|
-
end # Riot
|