riot 0.9.3 → 0.9.4

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.
@@ -4,20 +4,20 @@ An extremely fast, expressive, and context-driven unit-testing framework. Protes
4
4
 
5
5
  ### Note on speed
6
6
 
7
- I have done a really simple benchmarking, but right now, Riot is running about **10-times** faster than Test::unit and thusly Shoulda:
7
+ 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:
8
8
 
9
9
  $ ruby test/benchmark/simple_context_and_assertions.rb
10
10
 
11
11
  Rehearsal ----------------------------------------------
12
- Riot 0.140000 0.010000 0.150000 ( 0.156170)
13
- Test::Unit 1.460000 0.000000 1.460000 ( 1.495990)
14
- Shoulda 1.490000 0.010000 1.500000 ( 1.514745)
15
- ------------------------------------- total: 3.110000sec
12
+ Riot 0.670000 0.010000 0.680000 ( 0.688571)
13
+ Test::Unit 1.380000 0.010000 1.390000 ( 1.395437)
14
+ Shoulda 1.380000 0.000000 1.380000 ( 1.391839)
15
+ ------------------------------------- total: 3.450000sec
16
16
 
17
17
  user system total real
18
- Riot 0.130000 0.000000 0.130000 ( 0.139770)
19
- Test::Unit 1.600000 0.010000 1.610000 ( 1.627493)
20
- Shoulda 1.610000 0.010000 1.620000 ( 1.655394)
18
+ Riot 0.650000 0.010000 0.660000 ( 0.657817)
19
+ Test::Unit 1.350000 0.000000 1.350000 ( 1.362907)
20
+ Shoulda 1.380000 0.010000 1.390000 ( 1.388928)
21
21
 
22
22
  Loaded suite test/benchmark/simple_context_and_assertions
23
23
 
@@ -239,10 +239,8 @@ Create or modify your existing Rakefile to define a test task like so:
239
239
 
240
240
  desc "Run all tests"
241
241
  task :test do
242
- require 'riot'
243
242
  $:.concat ['./lib', './test']
244
- Dir.glob("./test/*_test.rb").each { |test| require test }
245
- Riot.report
243
+ Dir.glob("./test/**/*_test.rb").each { |test| require test }
246
244
  end
247
245
 
248
246
  Then, from the command line, you only need to run `rake` or `rake test`. Please make sure to remove all references to any other testing frameworks before running tests. For instance, do not require `test/unit`, `shoulda`, `minitest`, or anything else like it.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ task :default => [:test]
6
6
  desc "Run tests"
7
7
  task :test do
8
8
  $:.concat ['./test', './lib']
9
- Dir.glob("./test/*_test.rb").each { |test| require test }
9
+ Dir.glob("./test/**/*_test.rb").each { |test| require test }
10
10
  end
11
11
 
12
12
  desc "Run Flog against library (except tests)"
@@ -4,57 +4,42 @@ require 'riot/assertion'
4
4
  require 'riot/macros'
5
5
 
6
6
  module Riot
7
- #
8
- # Initializing logic
9
- def self.contexts
10
- @contexts ||= []
11
- end
12
7
 
13
8
  def self.context(description, reporter = nil, parent = nil, &block)
14
9
  reporter ||= self.reporter
15
10
  context = Context.new(description, reporter, parent)
16
- reporter.time { context.instance_eval(&block) }
17
- context.report # Results get buffered this way, not necessarily the best
18
- (contexts << context).last
19
- end
20
-
21
- def self.dequeue_context(context)
22
- contexts.delete(context)
23
- end
24
-
25
- def self.report
26
- reporter.results
27
- at_exit { exit false unless reporter.passed? }
11
+ if block_given?
12
+ reporter.time { context.instance_eval(&block) }
13
+ context.report # Results get buffered this way, not necessarily the best
14
+ end
15
+ context
28
16
  end
29
17
 
30
18
  #
31
19
  # Reporter
32
20
 
33
- def self.reporter; @reporter ||= TextReport.new; end
21
+ def self.reporter; @reporter ||= (Riot.silently? ? NilReport.new : TextReport.new); end
34
22
  def self.reporter=(report); @reporter = report; end
35
23
  def self.silently!; @silently = true; end
36
24
  def self.silently?; @silently || false; end
37
25
 
26
+ def self.report
27
+ reporter.results
28
+ at_exit { exit false unless reporter.passed? }
29
+ end
30
+
31
+ at_exit { Riot.report unless Riot.silently? }
32
+
38
33
  #
39
- # Exception
34
+ # Exceptions
40
35
 
41
36
  class Failure < Exception
42
- attr_accessor :assertion, :context
43
- def initialize(message, assertion=nil)
44
- super(message)
45
- @assertion = assertion
46
- end
47
-
48
- def contextualize(ctx)
49
- @context = ctx
50
- self
51
- end
52
-
53
37
  def print_stacktrace?; false; end
54
38
  end
39
+
55
40
  class Error < Failure
56
- def initialize(message, assertion, error)
57
- super(message, assertion)
41
+ def initialize(message, error)
42
+ super(message)
58
43
  set_backtrace(error.backtrace)
59
44
  end
60
45
  def print_stacktrace?; true; end
@@ -14,7 +14,7 @@ module Riot
14
14
  end
15
15
 
16
16
  def fail(message)
17
- @failure = Failure.new(message, self) unless errored?
17
+ @failure = Failure.new("#{description}: #{message}") unless errored?
18
18
  end
19
19
 
20
20
  def failed?; !@failure.nil?; end
@@ -27,13 +27,12 @@ module Riot
27
27
  @default_failure = fail("expected true, not #{@actual.inspect}") unless @actual == true
28
28
  rescue Failure => e
29
29
  @failure = e
30
- @failure.assertion = self
31
30
  rescue Exception => e
32
31
  @raised = e
33
32
  end
34
33
 
35
34
  def error
36
- Error.new("errored with #{@raised}", self, @raised) if errored?
35
+ Error.new("#{description}: errored with #{@raised}", @raised) if errored?
37
36
  end
38
37
  end # Assertion
39
38
  end # Riot
@@ -32,23 +32,14 @@ module Riot
32
32
  def asserts(description, &block) new_assertion("asserts #{description}", &block); end
33
33
  def should(description, &block) new_assertion("should #{description}", &block); end
34
34
 
35
- # In conclusion
36
35
  def report
37
- # we should just be passing assertions to the reporter and building better descriptions earlier
38
- assertions.each do |assertion|
39
- if assertion.passed?
40
- @reporter.passed
41
- else
42
- result = assertion.result.contextualize(self)
43
- @reporter.send( (assertion.errored? ? :errored : :failed), result)
44
- end
45
- end
36
+ assertions.each { |assertion| @reporter.process_assertion(assertion) }
46
37
  end
47
38
 
48
39
  def to_s; @to_s ||= [@parent.to_s, @description].join(' ').strip; end
49
40
  private
50
41
  def new_assertion(description, &block)
51
- (assertions << Assertion.new(description, @situation, &block)).last
42
+ (assertions << Assertion.new("#{to_s} #{description}", @situation, &block)).last
52
43
  end
53
44
 
54
45
  def induce_local_setup(a_situation)
@@ -17,6 +17,14 @@ module Riot
17
17
  @time_taken += (Time.now - @start).to_f
18
18
  end
19
19
 
20
+ def process_assertion(assertion)
21
+ if assertion.passed?
22
+ passed
23
+ else
24
+ send((assertion.errored? ? :errored : :failed), assertion.result)
25
+ end
26
+ end
27
+
20
28
  def passed; @passes += 1; end
21
29
 
22
30
  def failed(failure)
@@ -30,25 +38,27 @@ module Riot
30
38
  end
31
39
  end # Report
32
40
 
41
+ class NilReport < Report
42
+ def results; end
43
+ def time(&block); yield; end
44
+ end # NilReport
45
+
33
46
  class TextReport < Report
34
47
  def initialize(writer=nil)
35
48
  super()
36
- @writer ||= (Riot.silently? ? StringIO.new : STDOUT)
49
+ @writer ||= STDOUT
37
50
  end
38
51
 
39
52
  def passed
40
- super
41
- @writer.print('.')
53
+ super && @writer.print('.')
42
54
  end
43
55
 
44
56
  def failed(failure)
45
- super
46
- @writer.print('F')
57
+ super && @writer.print('F')
47
58
  end
48
59
 
49
60
  def errored(error)
50
- super
51
- @writer.print('E')
61
+ super && @writer.print('E')
52
62
  end
53
63
 
54
64
  def results
@@ -66,14 +76,6 @@ module Riot
66
76
  end
67
77
  end
68
78
 
69
- def render_result(idx, result)
70
- format_args = [idx, result.context.to_s, result.assertion.to_s, result.to_s]
71
- "#%d - %s %s: %s" % format_args
72
- end
79
+ def render_result(idx, result) "#%d - %s" % [idx, result.to_s]; end
73
80
  end # TextReport
74
-
75
- class NilReport < Report
76
- def results; end
77
- def time(&block); yield; end
78
- end # NilReport
79
81
  end # Riot
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "riot"
3
- s.version = "0.9.3"
3
+ s.version = "0.9.4"
4
4
  s.date = "2009-10-06"
5
5
  s.summary = "An extremely fast, expressive, and context-driven unit-testing framework"
6
6
  s.email = %w[gus@gusg.us]
@@ -26,13 +26,13 @@ Gem::Specification.new do |s|
26
26
 
27
27
  s.test_files = %w[
28
28
  Rakefile
29
- test/assertion_macro_assigns_test.rb
30
- test/assertion_macro_equals_test.rb
31
- test/assertion_macro_exists_test.rb
32
- test/assertion_macro_kind_of_test.rb
33
- test/assertion_macro_matching_test.rb
34
- test/assertion_macro_nil_test.rb
35
- test/assertion_macro_raises_test.rb
29
+ test/assertion_macros/assertion_macro_assigns_test.rb
30
+ test/assertion_macros/assertion_macro_equals_test.rb
31
+ test/assertion_macros/assertion_macro_exists_test.rb
32
+ test/assertion_macros/assertion_macro_kind_of_test.rb
33
+ test/assertion_macros/assertion_macro_matching_test.rb
34
+ test/assertion_macros/assertion_macro_nil_test.rb
35
+ test/assertion_macros/assertion_macro_raises_test.rb
36
36
  test/assertion_test.rb
37
37
  test/benchmark/simple_context_and_assertions.rb
38
38
  test/context_test.rb
@@ -1,6 +1,6 @@
1
1
  require 'teststrap'
2
2
 
3
- context "assigns assertion:" do
3
+ context "assigns assertion" do
4
4
  setup do
5
5
  @fake_situation = Riot::Situation.new
6
6
  object_with_instance_variables = Riot::Situation.new
@@ -21,7 +21,7 @@ context "assigns assertion:" do
21
21
  asserts "an instance variable was defined with nil value" do
22
22
  test_object = topic
23
23
  Riot::Assertion.new("foo", @fake_situation) { test_object }.assigns(:bar).message
24
- end.equals("expected @bar to be assigned a value")
24
+ end.matches(/expected @bar to be assigned a value/)
25
25
 
26
26
  asserts("an instance variable was assigned a specific value") do
27
27
  test_object = topic
@@ -31,10 +31,10 @@ context "assigns assertion:" do
31
31
  asserts("failure when instance never assigned even when a value is expected") do
32
32
  test_object = topic
33
33
  Riot::Assertion.new("duh", @fake_situation) { test_object }.assigns(:bar, "bar").message
34
- end.equals("expected @bar to be assigned a value")
34
+ end.matches(/expected @bar to be assigned a value/)
35
35
 
36
36
  asserts("failure when expected value is not assigned to variable with a value") do
37
37
  test_object = topic
38
38
  Riot::Assertion.new("duh", @fake_situation) { test_object }.assigns(:foo, "baz").message
39
- end.equals("expected @foo to be equal to 'baz', not 'bar'")
39
+ end.matches(/expected @foo to be equal to 'baz', not 'bar'/)
40
40
  end # assigns assertion
@@ -1,6 +1,6 @@
1
1
  require 'teststrap'
2
2
 
3
- context "basic assertion:" do
3
+ context "basic assertion" do
4
4
  setup { Riot::Situation.new }
5
5
 
6
6
  should "have a description" do
@@ -19,7 +19,7 @@ context "basic assertion:" do
19
19
  Riot::Assertion.new("error", topic) { raise Exception, "blah" }.errored?
20
20
  end
21
21
 
22
- context "that fails while executing test" do
22
+ context "that fails while executing a test" do
23
23
  setup do
24
24
  fake_situation = Riot::Situation.new
25
25
  Riot::Assertion.new("error", fake_situation) { fail("I'm a bum") }
@@ -27,6 +27,5 @@ context "basic assertion:" do
27
27
 
28
28
  should("be considered a failing assertion") { topic.failed? }
29
29
  should("use failed message in description") { topic.result.message }.matches(/I'm a bum/)
30
- should("assign assertion to failure") { topic.result }.assigns(:assertion)
31
30
  end # that fails while executing test
32
31
  end # basic assertion
@@ -11,23 +11,11 @@ class Room
11
11
  end
12
12
  end
13
13
 
14
- #
15
- # Riot
16
-
17
- require 'riot'
18
- Riot.silently! # Do this before any contexts are defined
19
-
20
- context "a room" do
21
- setup { @room = Room.new("bed") }
22
-
23
- asserts("name") { @room.name }.equals("bed")
24
- end # a room
25
-
26
14
  #
27
15
  # Test::Unit
28
16
 
29
17
  require 'test/unit'
30
- Test::Unit.run = false
18
+ Test::Unit.run = true
31
19
 
32
20
  require 'test/unit/ui/console/testrunner'
33
21
 
@@ -55,6 +43,12 @@ class ShouldaRoomTest < Test::Unit::TestCase
55
43
  should("be named 'bed'") { assert_equal "bed", @room.name }
56
44
  end
57
45
 
46
+ #
47
+ # Riot
48
+
49
+ require 'riot'
50
+ Riot.silently!
51
+
58
52
  #
59
53
  # Benchmarking
60
54
 
@@ -62,7 +56,13 @@ n = 100 * 100
62
56
 
63
57
  Benchmark.bmbm do |x|
64
58
  x.report("Riot") do
65
- n.times { Riot.report }
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
66
66
  end
67
67
 
68
68
  x.report("Test::Unit") do
@@ -1,5 +1,4 @@
1
1
  require 'teststrap'
2
- require 'stringio'
3
2
 
4
3
  context "any context" do
5
4
  setup do
@@ -30,56 +29,46 @@ context "any context" do
30
29
  end # any context
31
30
 
32
31
  #
33
- # Test Context
32
+ # Basic Context
34
33
 
35
- test_context = context("foo", Riot::NilReport.new) do
36
- setup { @test_counter = 0 }
37
- asserts("truthiness") { @test_counter += 1; true }
38
- asserts("more truthiness") { @test_counter += 1; true }
39
- end # A CONTEXT THAT IS DEQUEUED
40
-
41
- context "test context" do
42
- setup { Riot.dequeue_context(test_context) }
43
- should("confirm context description") { test_context.to_s }.equals("foo")
44
- should("confirm assertion count") { test_context.assertions.length }.equals(2)
34
+ context "basic context" do
35
+ setup do
36
+ test_context = Riot::Context.new("foo", Riot::NilReport.new)
37
+ test_context.setup { @test_counter = 0 }
38
+ test_context.asserts("truthiness") { @test_counter += 1; true }
39
+ test_context.asserts("more truthiness") { @test_counter += 1; true }
40
+ test_context
41
+ end
45
42
 
46
- should("call setup once per context") do
47
- test_context.situation.instance_variable_get(:@test_counter) # yuck
48
- end.equals(2)
49
- end # test context
43
+ asserts("context description") { topic.to_s }.equals("foo")
44
+ asserts("assertion count") { topic.assertions.length }.equals(2)
45
+ should("call setup once per context") { topic.situation }.assigns(:test_counter, 2)
46
+ end # basic context
50
47
 
51
48
  #
52
49
  # Nested Context
53
50
 
54
- inner_nested_context, other_nested_context = nil, nil
55
- nested_context = context("foo", Riot::NilReport.new) do
51
+ context "nested context" do
56
52
  setup do
57
- @test_counter = 0
58
- @foo = "bar"
53
+ @parent_context = Riot::Context.new("foo", Riot::NilReport.new)
54
+ @parent_context.setup { @test_counter = 0; @foo = "bar" }
55
+ @parent_context.asserts("truthiness") { @test_counter += 1; true }
56
+ @parent_context
59
57
  end
60
- asserts("truthiness") { @test_counter += 1; true }
61
58
 
62
- inner_nested_context = context("baz") do
63
- setup { @test_counter += 10 }
64
- end # A CONTEXT THAT IS DEQUEUED
65
-
66
- other_nested_context = context("bum") {} # A CONTEXT THAT IS DEQUEUED
67
- end # A CONTEXT THAT IS DEQUEUED
68
-
69
- context "nested context" do
70
- setup do
71
- [nested_context, inner_nested_context, other_nested_context].each do |c|
72
- Riot.dequeue_context(c)
59
+ context "inner context with own setup" do
60
+ setup do
61
+ test_context = @parent_context.context("baz")
62
+ test_context.setup { @test_counter += 10 }
63
+ test_context
73
64
  end
74
- end
75
65
 
76
- should("inherit parent context") do
77
- inner_nested_context.situation.instance_variable_get(:@test_counter)
78
- end.equals(10)
79
-
80
- should("chain context names") { inner_nested_context.to_s }.equals("foo baz")
66
+ should("inherit parent context") { topic.situation }.assigns(:test_counter, 10)
67
+ should("chain context names") { topic.to_s }.equals("foo baz")
68
+ end
81
69
 
82
- asserts "parent setup is called even if setup not defined for self" do
83
- other_nested_context.situation.instance_variable_get(:@foo)
84
- end.equals("bar")
70
+ context "inner context without its own setup" do
71
+ setup { @parent_context.context("bum") }
72
+ asserts("parent setup is called") { topic.situation }.assigns(:foo, "bar")
73
+ end
85
74
  end
@@ -1,3 +1 @@
1
1
  require 'riot'
2
-
3
- at_exit { Riot.report }
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.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Knowlden
@@ -62,13 +62,13 @@ specification_version: 3
62
62
  summary: An extremely fast, expressive, and context-driven unit-testing framework
63
63
  test_files:
64
64
  - Rakefile
65
- - test/assertion_macro_assigns_test.rb
66
- - test/assertion_macro_equals_test.rb
67
- - test/assertion_macro_exists_test.rb
68
- - test/assertion_macro_kind_of_test.rb
69
- - test/assertion_macro_matching_test.rb
70
- - test/assertion_macro_nil_test.rb
71
- - test/assertion_macro_raises_test.rb
65
+ - test/assertion_macros/assertion_macro_assigns_test.rb
66
+ - test/assertion_macros/assertion_macro_equals_test.rb
67
+ - test/assertion_macros/assertion_macro_exists_test.rb
68
+ - test/assertion_macros/assertion_macro_kind_of_test.rb
69
+ - test/assertion_macros/assertion_macro_matching_test.rb
70
+ - test/assertion_macros/assertion_macro_nil_test.rb
71
+ - test/assertion_macros/assertion_macro_raises_test.rb
72
72
  - test/assertion_test.rb
73
73
  - test/benchmark/simple_context_and_assertions.rb
74
74
  - test/context_test.rb