riot 0.9.12 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +1 -0
  2. data/README.markdown +37 -45
  3. data/VERSION +1 -1
  4. data/lib/riot.rb +27 -18
  5. data/lib/riot/assertion_macros.rb +63 -53
  6. data/lib/riot/context.rb +26 -36
  7. data/lib/riot/reporter.rb +77 -0
  8. data/lib/riot/runnable.rb +50 -0
  9. data/lib/riot/situation.rb +6 -3
  10. data/riot.gemspec +30 -21
  11. data/test/assertion_macros/assigns_test.rb +24 -0
  12. data/test/assertion_macros/equals_test.rb +18 -0
  13. data/test/assertion_macros/exists_test.rb +17 -0
  14. data/test/assertion_macros/kind_of_test.rb +17 -0
  15. data/test/assertion_macros/matching_test.rb +12 -0
  16. data/test/assertion_macros/nil_test.rb +13 -0
  17. data/test/assertion_macros/raises_test.rb +33 -0
  18. data/test/assertion_macros/respond_to_test.rb +12 -0
  19. data/test/assertion_macros/same_elements_test.rb +17 -0
  20. data/test/assertion_test.rb +25 -22
  21. data/test/benchmark/riot_vs_minitest.rb +8 -8
  22. data/test/benchmark/same_elements_vs_set.rb +41 -0
  23. data/test/benchmark/simple_context_and_assertions.rb +8 -8
  24. data/test/context_test.rb +68 -83
  25. data/test/report_test.rb +44 -0
  26. data/test/setup_test.rb +17 -0
  27. data/test/situation_test.rb +16 -0
  28. data/test/teststrap.rb +31 -0
  29. metadata +30 -21
  30. data/lib/riot/assertion.rb +0 -37
  31. data/lib/riot/errors.rb +0 -15
  32. data/lib/riot/report.rb +0 -82
  33. data/test/assertion_macros/assertion_macro_assigns_test.rb +0 -40
  34. data/test/assertion_macros/assertion_macro_equals_test.rb +0 -13
  35. data/test/assertion_macros/assertion_macro_exists_test.rb +0 -17
  36. data/test/assertion_macros/assertion_macro_kind_of_test.rb +0 -13
  37. data/test/assertion_macros/assertion_macro_matching_test.rb +0 -17
  38. data/test/assertion_macros/assertion_macro_nil_test.rb +0 -13
  39. data/test/assertion_macros/assertion_macro_raises_test.rb +0 -43
  40. data/test/assertion_macros/assertion_macro_respond_to_test.rb +0 -16
@@ -15,7 +15,12 @@ end
15
15
  # Riot
16
16
 
17
17
  require 'riot'
18
- Riot.silently!
18
+
19
+ context "a room" do
20
+ setup { Room.new("bed") }
21
+
22
+ asserts("name") { topic.name }.equals("bed")
23
+ end # a room
19
24
 
20
25
  #
21
26
  # MiniTest::Unit
@@ -40,13 +45,8 @@ n = 100 * 100
40
45
 
41
46
  Benchmark.bmbm do |x|
42
47
  x.report("Riot") do
43
- n.times do
44
- context "a room" do
45
- setup { Room.new("bed") }
46
-
47
- asserts("name") { topic.name }.equals("bed")
48
- end # a room
49
- end
48
+ Riot.silently!
49
+ n.times { Riot.run }
50
50
  end
51
51
 
52
52
  x.report("MiniTest") do
@@ -0,0 +1,41 @@
1
+ require 'benchmark'
2
+
3
+ #
4
+ # Benchmarking
5
+
6
+ n = 100 * 100
7
+
8
+ Benchmark.bmbm do |x|
9
+ x.report("Set theory") do
10
+ require 'set'
11
+ def set_theory(expected, actual)
12
+ a = Set.new(expected)
13
+ b = Set.new(actual)
14
+ a == b
15
+ end
16
+
17
+ n.times do
18
+ array = ["a", 1, {:foo => :bar}]
19
+ set_theory(array, array.reverse)
20
+ end
21
+ end
22
+
23
+ x.report("same_elements from shoulda (sorta)") do
24
+ def same_elements(a1, a2)
25
+ [:select, :inject, :size].each do |m|
26
+ [a1, a2].each { |a| a.respond_to?(m) || return }
27
+ end
28
+
29
+ a1h = a1.inject({}) { |h,e| h[e] = a1.select { |i| i == e }.size; h }
30
+ a2h = a2.inject({}) { |h,e| h[e] = a2.select { |i| i == e }.size; h }
31
+
32
+ a1h == a2h
33
+ end
34
+
35
+ n.times do
36
+ array = ["a", 1, {:foo => :bar}]
37
+ same_elements(array, array.reverse)
38
+ end
39
+ end
40
+ end
41
+
@@ -47,7 +47,12 @@ end
47
47
  # Riot
48
48
 
49
49
  require 'riot'
50
- Riot.silently!
50
+
51
+ context "a room" do
52
+ setup { Room.new("bed") }
53
+
54
+ asserts("name") { topic.name }.equals("bed")
55
+ end # a room
51
56
 
52
57
  #
53
58
  # Benchmarking
@@ -56,13 +61,8 @@ n = 100 * 100
56
61
 
57
62
  Benchmark.bmbm do |x|
58
63
  x.report("Riot") do
59
- n.times do
60
- context "a room" do
61
- setup { @room = Room.new("bed") }
62
-
63
- asserts("name") { @room.name }.equals("bed")
64
- end # a room
65
- end
64
+ Riot.silently!
65
+ n.times { Riot.run }
66
66
  end
67
67
 
68
68
  x.report("Test::Unit") do
@@ -1,105 +1,90 @@
1
1
  require 'teststrap'
2
2
 
3
- context "any context" do
3
+ context "Reporting a context" do
4
4
  setup do
5
- @reporter = Riot::NilReport.new
6
- @context = Riot::Context.new("a", @reporter)
7
- end
8
-
9
- context "that doesn't have passing tests" do
10
- setup do
11
- @context.should("a") { true }
12
- @context.should("b") { false }
13
- @context.should("c") { raise Exception, "blah" }
14
- @context.report
5
+ a_context = Riot::Context.new("foobar") do
6
+ asserts("passing") { true }
7
+ asserts("failing") { false }
8
+ asserts("erroring") { raise Exception }
15
9
  end
10
+ a_context.run(MockReporter.new)
11
+ end
16
12
 
17
- asserts("passed test count") { @reporter.passes }.equals(1)
18
- asserts("failure count") { @reporter.failures }.equals(1)
19
- asserts("unexpected errors count") { @reporter.errors }.equals(1)
20
- end # that doesn't have passing tests
21
-
22
- context "when running setup:" do
23
- setup { @context.setup { "foo" } }
24
-
25
- asserts "topic becomes available to test as result of setup" do
26
- @context.should("bar") { topic }.actual
27
- end.equals("foo")
28
-
29
- asserts "calling topic in context will return assertion that returns topic as the actual" do
30
- @context.topic.actual
31
- end.equals("foo")
32
- end # when running setup
33
- end # any context
34
-
35
- #
36
- # Basic Context
13
+ asserts("one passed test") { topic.passes == 1 }
14
+ asserts("one failed test") { topic.failures == 1 }
15
+ asserts("one errored test") { topic.errors == 1 }
16
+ end # Reporting a context
37
17
 
38
- context "basic context" do
18
+ context "Defining a context with multiple setups" do
39
19
  setup do
40
- test_context = Riot::Context.new("foo", Riot::NilReport.new)
41
- test_context.setup { @test_counter = 0 }
42
- test_context.asserts("truthiness") { @test_counter += 1; true }
43
- test_context.asserts("more truthiness") { @test_counter += 1; true }
44
- test_context
20
+ a_context = Riot::Context.new("foobar") do
21
+ setup { "foo" }
22
+ setup { topic + "bar" }
23
+ asserts("blah") { topic == "foobar" }
24
+ end
25
+ a_context.run(MockReporter.new)
45
26
  end
46
27
 
47
- asserts("context description") { topic.to_s }.equals("foo")
48
- asserts("assertion count") { topic.assertions.length }.equals(2)
49
- should("call setup once per context") { topic.situation }.assigns(:test_counter, 2)
50
- end # basic context
51
-
52
- #
53
- # Nested Context
28
+ asserts("all tests pass") { topic.passes == 1 }
29
+ end # Defining a context with multiple setups
54
30
 
55
- context "nested context" do
31
+ context "Nesting a context" do
56
32
  setup do
57
- test_context = Riot::Context.new("foo", Riot::NilReport.new)
58
- test_context.setup { @test_counter = 0; @foo = "bar" }
59
- test_context.asserts("truthiness") { @test_counter += 1; true }
60
- test_context
33
+ a_context = Riot::Context.new("foobar") do
34
+ asserts("passing") { true }
35
+ context "bazboo" do
36
+ asserts("passing") { true }
37
+ asserts("failing") { false }
38
+ asserts("erroring") { raise Exception }
39
+ end
40
+ end
41
+ a_context.run(MockReporter.new)
61
42
  end
62
-
63
- context "inner context with own setup" do
43
+
44
+ asserts("one passed test") { topic.passes == 2 }
45
+ asserts("one failed test") { topic.failures == 1 }
46
+ asserts("one errored test") { topic.errors == 1 }
47
+
48
+ context "with setups" do
64
49
  setup do
65
- test_context = topic.context("baz")
66
- test_context.setup { @test_counter += 10 }
67
- test_context
50
+ a_context = Riot::Context.new("foobar") do
51
+ setup { "foo" }
52
+ context "bazboo" do
53
+ setup { topic + "bar" }
54
+ asserts("passing") { topic == "foobar" }
55
+ end
56
+ end
57
+ a_context.run(MockReporter.new)
68
58
  end
69
-
70
- should("inherit parent context") { topic.situation }.assigns(:test_counter, 10)
71
- should("chain context names") { topic.to_s }.equals("foo baz")
72
- end
73
59
 
74
- context "inner context without its own setup" do
75
- setup { topic.context("bum") }
76
- asserts("parent setup is called") { topic.situation }.assigns(:foo, "bar")
60
+ asserts("parent setups are called") { topic.passes == 1 }
61
+ end # with setups
62
+ end # Nestings a context
63
+
64
+ context "Using should" do
65
+ setup do
66
+ a_context = Riot::Context.new("foobar") do
67
+ should("pass") { true }
68
+ should("fail") { false }
69
+ should("error") { raise Exception }
70
+ end
71
+ a_context.run(MockReporter.new)
77
72
  end
78
- end
79
73
 
80
- #
81
- # Multiple setups in a context
74
+ asserts("one passed test") { topic.passes == 1 }
75
+ asserts("one failed test") { topic.failures == 1 }
76
+ asserts("one errored test") { topic.errors == 1 }
77
+ end # Using should
82
78
 
83
- context "multiple setups" do
79
+ context "The asserts_topic shortcut" do
84
80
  setup do
85
- test_context = Riot::Context.new("foo", Riot::NilReport.new)
86
- test_context.setup { @foo = "bar" }
87
- test_context.setup { @baz = "boo" }
88
- test_context
81
+ Riot::Context.new("foo") {}.asserts_topic
89
82
  end
90
83
 
91
- asserts("foo") { topic.situation }.assigns(:foo, "bar")
92
- asserts("bar") { topic.situation }.assigns(:baz, "boo")
93
-
94
- context "in the parent of a nested context" do
95
- setup do
96
- test_context = topic.context("goo")
97
- test_context.setup { @goo = "car" }
98
- test_context
99
- end
84
+ should("return an Assertion") { topic }.kind_of(Riot::Assertion)
100
85
 
101
- asserts("foo") { topic.situation }.assigns(:foo, "bar")
102
- asserts("bar") { topic.situation }.assigns(:baz, "boo")
103
- asserts("goo") { topic.situation }.assigns(:goo, "car")
104
- end # in the parent of a nested context
105
- end # multiple setups
86
+ should("return the actual topic as the result of evaling the assertion") do
87
+ (situation = Riot::Situation.new).topic = "bar"
88
+ topic.equals("bar").run(situation)
89
+ end.equals([:pass])
90
+ end # The asserts_topic shortcut
@@ -0,0 +1,44 @@
1
+ require 'teststrap'
2
+
3
+ context "A reporter" do
4
+ setup do
5
+ Class.new(Riot::Reporter) do
6
+ def pass(d) "passed(#{d})"; end
7
+ def fail(d, message) "failed(#{d}, #{message})"; end
8
+ def error(d, e) "errored(#{d}, #{e})"; end
9
+ end.new
10
+ end
11
+
12
+ # pass
13
+
14
+ asserts("pass count increase when :pass sent to #report") do
15
+ topic.report("", [:pass])
16
+ topic.passes
17
+ end.equals(1)
18
+
19
+ asserts("description sent to #pass") do
20
+ topic.report("hi mom", [:pass])
21
+ end.equals("passed(hi mom)")
22
+
23
+ # fail
24
+
25
+ asserts("fail count increase when :fail sent to #report") do
26
+ topic.report("", [:fail, ""])
27
+ topic.failures
28
+ end.equals(1)
29
+
30
+ asserts("description and message sent to #fail") do
31
+ topic.report("hi mom", [:fail, "how are you"])
32
+ end.equals("failed(hi mom, how are you)")
33
+
34
+ # error
35
+
36
+ asserts("error count increase when :error sent to #report") do
37
+ topic.report("", [:error, ""])
38
+ topic.errors
39
+ end.equals(1)
40
+
41
+ asserts("description sent to #error") do
42
+ topic.report("break it down", [:error, "error time"])
43
+ end.equals("errored(break it down, error time)")
44
+ end # A reporter
@@ -0,0 +1,17 @@
1
+ require 'teststrap'
2
+
3
+ context "A setup block" do
4
+ setup do
5
+ Riot::Setup.new { "fooberries" }
6
+ end
7
+
8
+ asserts("topic is set for situation when run") do
9
+ situation = Riot::Situation.new
10
+ topic.run(situation)
11
+ situation.topic == "fooberries"
12
+ end
13
+
14
+ asserts(":setup is returned from calling run") do
15
+ topic.run(Riot::Situation.new) == [:setup]
16
+ end
17
+ end # A setup block
@@ -0,0 +1,16 @@
1
+ require 'teststrap'
2
+
3
+ context "A situation" do
4
+ setup do
5
+ Riot::Situation.new
6
+ end
7
+
8
+ asserts("the topic is result of calling setup") do
9
+ topic.setup { "foo" }
10
+ topic.topic == "foo"
11
+ end
12
+
13
+ asserts("evaluate will return result of evaluation") do
14
+ topic.evaluate { "foo" == "bar" } == false
15
+ end
16
+ end # A situation
@@ -1 +1,32 @@
1
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
1
2
  require 'riot'
3
+
4
+ module Riot
5
+ module AssertionTestContextMacros
6
+
7
+ def assertion_test_passes(description, &block)
8
+ context(description) do
9
+ setup(&block)
10
+ asserts("passes") { topic.run(Riot::Situation.new) }.equals([:pass])
11
+ end
12
+ end
13
+
14
+ def assertion_test_fails(description, failure_message, &block)
15
+ context(description) do
16
+ setup(&block)
17
+ asserts("failure") { topic.run(Riot::Situation.new).first }.equals(:fail)
18
+ asserts("failure message") { topic.run(Riot::Situation.new).last }.equals(failure_message)
19
+ end
20
+ end
21
+
22
+ end # AssertionTestContextMacros
23
+ end # Riot
24
+
25
+ Riot::Context.instance_eval { include Riot::AssertionTestContextMacros }
26
+
27
+ class MockReporter < Riot::Reporter
28
+ def pass(description); end
29
+ def fail(description, message); end
30
+ def error(description, e); end
31
+ def results; end
32
+ 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.9.12
4
+ version: 0.10.0
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-10-22 00:00:00 -05:00
12
+ date: 2009-11-21 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,25 +28,29 @@ files:
28
28
  - Rakefile
29
29
  - VERSION
30
30
  - lib/riot.rb
31
- - lib/riot/assertion.rb
32
31
  - lib/riot/assertion_macros.rb
33
32
  - lib/riot/context.rb
34
- - lib/riot/errors.rb
35
- - lib/riot/report.rb
33
+ - lib/riot/reporter.rb
34
+ - lib/riot/runnable.rb
36
35
  - lib/riot/situation.rb
37
36
  - riot.gemspec
38
- - test/assertion_macros/assertion_macro_assigns_test.rb
39
- - test/assertion_macros/assertion_macro_equals_test.rb
40
- - test/assertion_macros/assertion_macro_exists_test.rb
41
- - test/assertion_macros/assertion_macro_kind_of_test.rb
42
- - test/assertion_macros/assertion_macro_matching_test.rb
43
- - test/assertion_macros/assertion_macro_nil_test.rb
44
- - test/assertion_macros/assertion_macro_raises_test.rb
45
- - test/assertion_macros/assertion_macro_respond_to_test.rb
37
+ - test/assertion_macros/assigns_test.rb
38
+ - test/assertion_macros/equals_test.rb
39
+ - test/assertion_macros/exists_test.rb
40
+ - test/assertion_macros/kind_of_test.rb
41
+ - test/assertion_macros/matching_test.rb
42
+ - test/assertion_macros/nil_test.rb
43
+ - test/assertion_macros/raises_test.rb
44
+ - test/assertion_macros/respond_to_test.rb
45
+ - test/assertion_macros/same_elements_test.rb
46
46
  - test/assertion_test.rb
47
47
  - test/benchmark/riot_vs_minitest.rb
48
+ - test/benchmark/same_elements_vs_set.rb
48
49
  - test/benchmark/simple_context_and_assertions.rb
49
50
  - test/context_test.rb
51
+ - test/report_test.rb
52
+ - test/setup_test.rb
53
+ - test/situation_test.rb
50
54
  - test/teststrap.rb
51
55
  has_rdoc: true
52
56
  homepage: http://github.com/thumblemonks/riot
@@ -77,16 +81,21 @@ signing_key:
77
81
  specification_version: 3
78
82
  summary: An extremely fast, expressive, and context-driven unit-testing framework. Protest the slow test.
79
83
  test_files:
80
- - test/assertion_macros/assertion_macro_assigns_test.rb
81
- - test/assertion_macros/assertion_macro_equals_test.rb
82
- - test/assertion_macros/assertion_macro_exists_test.rb
83
- - test/assertion_macros/assertion_macro_kind_of_test.rb
84
- - test/assertion_macros/assertion_macro_matching_test.rb
85
- - test/assertion_macros/assertion_macro_nil_test.rb
86
- - test/assertion_macros/assertion_macro_raises_test.rb
87
- - test/assertion_macros/assertion_macro_respond_to_test.rb
84
+ - test/assertion_macros/assigns_test.rb
85
+ - test/assertion_macros/equals_test.rb
86
+ - test/assertion_macros/exists_test.rb
87
+ - test/assertion_macros/kind_of_test.rb
88
+ - test/assertion_macros/matching_test.rb
89
+ - test/assertion_macros/nil_test.rb
90
+ - test/assertion_macros/raises_test.rb
91
+ - test/assertion_macros/respond_to_test.rb
92
+ - test/assertion_macros/same_elements_test.rb
88
93
  - test/assertion_test.rb
89
94
  - test/benchmark/riot_vs_minitest.rb
95
+ - test/benchmark/same_elements_vs_set.rb
90
96
  - test/benchmark/simple_context_and_assertions.rb
91
97
  - test/context_test.rb
98
+ - test/report_test.rb
99
+ - test/setup_test.rb
100
+ - test/situation_test.rb
92
101
  - test/teststrap.rb