riot 0.9.12 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.markdown +37 -45
- data/VERSION +1 -1
- data/lib/riot.rb +27 -18
- data/lib/riot/assertion_macros.rb +63 -53
- data/lib/riot/context.rb +26 -36
- data/lib/riot/reporter.rb +77 -0
- data/lib/riot/runnable.rb +50 -0
- data/lib/riot/situation.rb +6 -3
- data/riot.gemspec +30 -21
- data/test/assertion_macros/assigns_test.rb +24 -0
- data/test/assertion_macros/equals_test.rb +18 -0
- data/test/assertion_macros/exists_test.rb +17 -0
- data/test/assertion_macros/kind_of_test.rb +17 -0
- data/test/assertion_macros/matching_test.rb +12 -0
- data/test/assertion_macros/nil_test.rb +13 -0
- data/test/assertion_macros/raises_test.rb +33 -0
- data/test/assertion_macros/respond_to_test.rb +12 -0
- data/test/assertion_macros/same_elements_test.rb +17 -0
- data/test/assertion_test.rb +25 -22
- data/test/benchmark/riot_vs_minitest.rb +8 -8
- data/test/benchmark/same_elements_vs_set.rb +41 -0
- data/test/benchmark/simple_context_and_assertions.rb +8 -8
- data/test/context_test.rb +68 -83
- data/test/report_test.rb +44 -0
- data/test/setup_test.rb +17 -0
- data/test/situation_test.rb +16 -0
- data/test/teststrap.rb +31 -0
- metadata +30 -21
- data/lib/riot/assertion.rb +0 -37
- data/lib/riot/errors.rb +0 -15
- data/lib/riot/report.rb +0 -82
- data/test/assertion_macros/assertion_macro_assigns_test.rb +0 -40
- data/test/assertion_macros/assertion_macro_equals_test.rb +0 -13
- data/test/assertion_macros/assertion_macro_exists_test.rb +0 -17
- data/test/assertion_macros/assertion_macro_kind_of_test.rb +0 -13
- data/test/assertion_macros/assertion_macro_matching_test.rb +0 -17
- data/test/assertion_macros/assertion_macro_nil_test.rb +0 -13
- data/test/assertion_macros/assertion_macro_raises_test.rb +0 -43
- data/test/assertion_macros/assertion_macro_respond_to_test.rb +0 -16
data/lib/riot/assertion.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Riot
|
2
|
-
class Assertion
|
3
|
-
attr_reader :raised, :to_s, :description, :situation
|
4
|
-
def initialize(description, situation, &assertion_block)
|
5
|
-
@description = @to_s = description
|
6
|
-
@situation = situation
|
7
|
-
run(situation, &assertion_block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def actual
|
11
|
-
unfail_if_default_failure_recorded
|
12
|
-
@actual
|
13
|
-
end
|
14
|
-
|
15
|
-
def fail(message)
|
16
|
-
@failure = Failure.new("#{description}: #{message}") unless errored?
|
17
|
-
end
|
18
|
-
|
19
|
-
def passed?; !(failed? || errored?); end
|
20
|
-
def failed?; !@failure.nil?; end
|
21
|
-
def errored?; !@raised.nil?; end
|
22
|
-
def result; @failure || @raised; end
|
23
|
-
private
|
24
|
-
def run(situation, &assertion_block)
|
25
|
-
@actual = situation.instance_eval(&assertion_block)
|
26
|
-
@default_failure = fail("expected true, not #{@actual.inspect}") unless @actual == true
|
27
|
-
rescue Failure => e
|
28
|
-
@failure = e
|
29
|
-
rescue Exception => e
|
30
|
-
@raised = Error.new("#{description}: errored with #{e}", e)
|
31
|
-
end
|
32
|
-
|
33
|
-
def unfail_if_default_failure_recorded
|
34
|
-
@default_failure = @failure = nil if @default_failure
|
35
|
-
end
|
36
|
-
end # Assertion
|
37
|
-
end # Riot
|
data/lib/riot/errors.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Riot
|
2
|
-
class Failure < Exception
|
3
|
-
def print_stacktrace?; false; end
|
4
|
-
end
|
5
|
-
|
6
|
-
class Error < Failure
|
7
|
-
attr_reader :original_exception
|
8
|
-
def initialize(message, raised)
|
9
|
-
super(message)
|
10
|
-
set_backtrace(raised.backtrace)
|
11
|
-
@original_exception = raised
|
12
|
-
end
|
13
|
-
def print_stacktrace?; true; end
|
14
|
-
end
|
15
|
-
end # Riot
|
data/lib/riot/report.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
|
3
|
-
module Riot
|
4
|
-
class Report
|
5
|
-
attr_reader :bad_results, :passes, :failures, :errors, :time_taken
|
6
|
-
def initialize
|
7
|
-
@bad_results = []
|
8
|
-
@passes, @failures, @errors, @time_taken = 0, 0, 0, 0.0
|
9
|
-
end
|
10
|
-
|
11
|
-
def passed?; failures + errors == 0; end
|
12
|
-
def assertions; passes + failures + errors; end
|
13
|
-
|
14
|
-
def time(&block)
|
15
|
-
@start = Time.now
|
16
|
-
result = yield
|
17
|
-
@time_taken += (Time.now - @start).to_f
|
18
|
-
result
|
19
|
-
end
|
20
|
-
|
21
|
-
def process_assertion(assertion)
|
22
|
-
if assertion.passed?
|
23
|
-
passed
|
24
|
-
else
|
25
|
-
send((assertion.errored? ? :errored : :failed), assertion.result)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def passed; @passes += 1; end
|
30
|
-
|
31
|
-
def failed(failure)
|
32
|
-
@failures += 1
|
33
|
-
@bad_results << failure
|
34
|
-
end
|
35
|
-
|
36
|
-
def errored(error)
|
37
|
-
@errors += 1
|
38
|
-
@bad_results << error
|
39
|
-
end
|
40
|
-
end # Report
|
41
|
-
|
42
|
-
class NilReport < Report
|
43
|
-
def results; end
|
44
|
-
def time(&block); yield; end
|
45
|
-
end # NilReport
|
46
|
-
|
47
|
-
class TextReport < Report
|
48
|
-
def initialize(writer=nil)
|
49
|
-
super()
|
50
|
-
@writer ||= STDOUT
|
51
|
-
end
|
52
|
-
|
53
|
-
def passed
|
54
|
-
super && @writer.print('.')
|
55
|
-
end
|
56
|
-
|
57
|
-
def failed(failure)
|
58
|
-
super && @writer.print('F')
|
59
|
-
end
|
60
|
-
|
61
|
-
def errored(error)
|
62
|
-
super && @writer.print('E')
|
63
|
-
end
|
64
|
-
|
65
|
-
def results
|
66
|
-
@writer.puts "\n\n"
|
67
|
-
print_bad_results
|
68
|
-
format = "%d assertions, %d failures, %d errors in %s seconds"
|
69
|
-
@writer.puts format % [assertions, failures, errors, ("%0.6f" % time_taken)]
|
70
|
-
end
|
71
|
-
private
|
72
|
-
def print_bad_results
|
73
|
-
bad_results.each_with_index do |result, idx|
|
74
|
-
@writer.puts format_result(idx + 1, result)
|
75
|
-
@writer.puts " " + result.backtrace.join("\n ") if result.print_stacktrace?
|
76
|
-
@writer.puts "\n"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def format_result(idx, result) "#%d - %s" % [idx, result.to_s]; end
|
81
|
-
end # TextReport
|
82
|
-
end # Riot
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'teststrap'
|
2
|
-
|
3
|
-
context "assigns assertion" do
|
4
|
-
setup do
|
5
|
-
@fake_situation = Riot::Situation.new
|
6
|
-
object_with_instance_variables = Riot::Situation.new
|
7
|
-
object_with_instance_variables.instance_eval { @foo = "bar"; @bar = nil}
|
8
|
-
object_with_instance_variables
|
9
|
-
end
|
10
|
-
|
11
|
-
asserts("an instance variable was assigned") do
|
12
|
-
test_object = topic
|
13
|
-
Riot::Assertion.new("duh", @fake_situation) { test_object }.assigns(:foo)
|
14
|
-
end
|
15
|
-
|
16
|
-
asserts("an instance variable was never assigned") do
|
17
|
-
test_object = topic
|
18
|
-
Riot::Assertion.new("foo", @fake_situation) { test_object }.assigns(:baz)
|
19
|
-
end.kind_of(Riot::Failure)
|
20
|
-
|
21
|
-
asserts "an instance variable was defined with nil value" do
|
22
|
-
test_object = topic
|
23
|
-
Riot::Assertion.new("foo", @fake_situation) { test_object }.assigns(:bar).message
|
24
|
-
end.matches(/expected @bar to be assigned a value/)
|
25
|
-
|
26
|
-
asserts("an instance variable was assigned a specific value") do
|
27
|
-
test_object = topic
|
28
|
-
Riot::Assertion.new("duh", @fake_situation) { test_object }.assigns(:foo, "bar")
|
29
|
-
end
|
30
|
-
|
31
|
-
asserts("failure when instance never assigned even when a value is expected") do
|
32
|
-
test_object = topic
|
33
|
-
Riot::Assertion.new("duh", @fake_situation) { test_object }.assigns(:bar, "bar").message
|
34
|
-
end.matches(/expected @bar to be assigned a value/)
|
35
|
-
|
36
|
-
asserts("failure when expected value is not assigned to variable with a value") do
|
37
|
-
test_object = topic
|
38
|
-
Riot::Assertion.new("duh", @fake_situation) { test_object }.assigns(:foo, "baz").message
|
39
|
-
end.matches(/expected @foo to be equal to 'baz', not 'bar'/)
|
40
|
-
end # assigns assertion
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'teststrap'
|
2
|
-
|
3
|
-
context "equals assertion:" do
|
4
|
-
setup { Riot::Situation.new }
|
5
|
-
|
6
|
-
asserts "result equals expectation" do
|
7
|
-
Riot::Assertion.new("i will pass", topic) { "foo bar" }.equals("foo bar")
|
8
|
-
end
|
9
|
-
|
10
|
-
should "raise a Failure if results don't equal each other" do
|
11
|
-
Riot::Assertion.new("failure", topic) { "bar" }.equals("foo")
|
12
|
-
end.kind_of(Riot::Failure)
|
13
|
-
end # equals assertion
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'teststrap'
|
2
|
-
|
3
|
-
context "nil assertion:" do
|
4
|
-
setup { Riot::Situation.new }
|
5
|
-
|
6
|
-
asserts("result has a value") do
|
7
|
-
Riot::Assertion.new("foo", topic) { "foo" }.exists
|
8
|
-
end
|
9
|
-
|
10
|
-
asserts("empty string is considered a value") do
|
11
|
-
Riot::Assertion.new("foo", topic) { "" }.exists
|
12
|
-
end
|
13
|
-
|
14
|
-
should "raise a Failure if value is nil" do
|
15
|
-
Riot::Assertion.new("foo", topic) { nil }.exists
|
16
|
-
end.kind_of(Riot::Failure)
|
17
|
-
end # nil assertion
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'teststrap'
|
2
|
-
|
3
|
-
context "kind_of assertion:" do
|
4
|
-
setup { Riot::Situation.new }
|
5
|
-
|
6
|
-
asserts "specific result is a kind of String" do
|
7
|
-
Riot::Assertion.new("foo", topic) { "a" }.kind_of(String)
|
8
|
-
end
|
9
|
-
|
10
|
-
should "raise a Failure if not a kind of String" do
|
11
|
-
Riot::Assertion.new("foo", topic) { 0 }.kind_of(String)
|
12
|
-
end.kind_of(Riot::Failure)
|
13
|
-
end # kind_of assertion
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'teststrap'
|
2
|
-
|
3
|
-
context "matching assertion:" do
|
4
|
-
setup { Riot::Situation.new }
|
5
|
-
|
6
|
-
asserts "result matches expression" do
|
7
|
-
Riot::Assertion.new("foo", topic) { "a" }.matches(%r[.])
|
8
|
-
end.equals(0)
|
9
|
-
|
10
|
-
should "raise a Failure if result does not match" do
|
11
|
-
Riot::Assertion.new("foo", topic) { "" }.matches(%r[.])
|
12
|
-
end.kind_of(Riot::Failure)
|
13
|
-
|
14
|
-
should "return the result of a matching operation" do
|
15
|
-
Riot::Assertion.new("foo", topic) { "a" }.matches("a")
|
16
|
-
end.equals(0)
|
17
|
-
end # maching assertion
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'teststrap'
|
2
|
-
|
3
|
-
context "nil assertion:" do
|
4
|
-
setup { Riot::Situation.new }
|
5
|
-
|
6
|
-
asserts("result is nil") do
|
7
|
-
Riot::Assertion.new("foo", topic) { nil }.nil
|
8
|
-
end
|
9
|
-
|
10
|
-
should "raise a Failure if not nil" do
|
11
|
-
Riot::Assertion.new("foo", topic) { "a" }.nil
|
12
|
-
end.kind_of(Riot::Failure)
|
13
|
-
end # nil assertion
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'teststrap'
|
2
|
-
|
3
|
-
class MyException < Exception; end
|
4
|
-
|
5
|
-
context "raises assertion:" do
|
6
|
-
setup { Riot::Situation.new }
|
7
|
-
|
8
|
-
should("raise an Exception") { raise Exception }.raises(Exception)
|
9
|
-
|
10
|
-
should "fail if nothing was raised" do
|
11
|
-
assertion = Riot::Assertion.new("foo", topic) { "barf" }
|
12
|
-
assertion.raises(Exception)
|
13
|
-
assertion.result.message
|
14
|
-
end.matches(/should have raised Exception, but raised nothing/)
|
15
|
-
|
16
|
-
should "fail if Exception classes do not match" do
|
17
|
-
Riot::Assertion.new("foo", topic) { raise MyException }.raises(Exception)
|
18
|
-
end.kind_of(Riot::Failure)
|
19
|
-
|
20
|
-
should "pass if provided message equals expectation" do
|
21
|
-
Riot::Assertion.new("foo", topic) { raise Exception, "I'm a nerd" }.raises(Exception, "I'm a nerd")
|
22
|
-
end
|
23
|
-
|
24
|
-
should "fail if provided message does not equal expectation" do
|
25
|
-
Riot::Assertion.new("foo", topic) { raise(Exception, "I'm a nerd") }.raises(Exception, "But I'm not")
|
26
|
-
end.kind_of(Riot::Failure)
|
27
|
-
|
28
|
-
should "pass if provided message matches expectation" do
|
29
|
-
Riot::Assertion.new("foo", topic) { raise(Exception, "I'm a nerd") }.raises(Exception, /nerd/)
|
30
|
-
end
|
31
|
-
|
32
|
-
should "fail if provided message does not match expectation" do
|
33
|
-
Riot::Assertion.new("foo", topic) { raise(Exception, "I'm a nerd") }.raises(Exception, /foo/)
|
34
|
-
end.kind_of(Riot::Failure)
|
35
|
-
|
36
|
-
should "pass if provided message as array equals expectation" do
|
37
|
-
Riot::Assertion.new("foo", topic) { raise(Exception, ["foo", "bar"]) }.raises(Exception, "foobar")
|
38
|
-
end
|
39
|
-
|
40
|
-
should "pass if provided message as array matches expectation" do
|
41
|
-
Riot::Assertion.new("foo", topic) { raise(Exception, ["foo", "bar"]) }.raises(Exception, /oba/)
|
42
|
-
end
|
43
|
-
end # raises assertion
|
@@ -1,16 +0,0 @@
|
|
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
|