riot 0.10.5 → 0.10.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.5
1
+ 0.10.6
@@ -1,5 +1,10 @@
1
1
  module Riot
2
- RootContext = Struct.new(:setups, :teardowns)
2
+ RootContext = Struct.new(:setups, :teardowns) do
3
+ def assertion_class
4
+ Assertion
5
+ end
6
+ end
7
+
3
8
  class Context
4
9
  attr_reader :description
5
10
  def initialize(description, parent=RootContext.new([],[]), &definition)
@@ -20,16 +25,28 @@ module Riot
20
25
  def asserts_topic; asserts("topic") { topic }; end
21
26
 
22
27
  def context(description, &definition)
23
- @contexts << Context.new("#{@description} #{description}", self, &definition)
28
+ @contexts << self.class.new("#{@description} #{description}", self, &definition)
24
29
  end
25
30
 
31
+ def extend_assertions(*extension_modules)
32
+ @assertion_class = Class.new(Assertion) do
33
+ include *extension_modules
34
+ end
35
+ end
36
+
26
37
  def run(reporter)
27
38
  reporter.describe_context(self) unless @assertions.empty?
28
39
  local_run(reporter, Situation.new)
29
40
  run_sub_contexts(reporter)
30
41
  reporter
31
42
  end
43
+
44
+ def assertion_class
45
+ @assertion_class ||= @parent.assertion_class
46
+ end
47
+
32
48
  private
49
+
33
50
  def local_run(reporter, situation)
34
51
  (setups + @assertions + teardowns).each do |runnable|
35
52
  reporter.report(runnable.to_s, runnable.run(situation))
@@ -39,7 +56,7 @@ module Riot
39
56
  def run_sub_contexts(reporter) @contexts.each { |ctx| ctx.run(reporter) }; end
40
57
 
41
58
  def new_assertion(scope, what, &definition)
42
- (@assertions << Assertion.new("#{scope} #{what}", &definition)).last
59
+ (@assertions << assertion_class.new("#{scope} #{what}", &definition)).last
43
60
  end
44
61
  end # Context
45
62
  end # Riot
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{riot}
8
- s.version = "0.10.5"
8
+ s.version = "0.10.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin 'Gus' Knowlden"]
12
- s.date = %q{2009-12-14}
12
+ s.date = %q{2009-12-15}
13
13
  s.description = %q{An extremely fast, expressive, and context-driven unit-testing framework. A replacement for all other testing frameworks. Protest the slow test.}
14
14
  s.email = %q{gus@gusg.us}
15
15
  s.extra_rdoc_files = [
@@ -88,3 +88,55 @@ context "The asserts_topic shortcut" do
88
88
  topic.equals("bar").run(situation)
89
89
  end.equals([:pass])
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
@@ -54,7 +54,7 @@ context "StoryReporter" do
54
54
  setup do
55
55
  @out = StringIO.new
56
56
  Riot::StoryReporter.new(@out)
57
- emd
57
+ end
58
58
 
59
59
  context 'reporting on an empty context' do
60
60
  setup do
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.5
4
+ version: 0.10.6
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-14 00:00:00 -06:00
12
+ date: 2009-12-15 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency