micronaut 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/History.txt +15 -0
  2. data/LICENSE +45 -0
  3. data/README.markdown +66 -0
  4. data/RSPEC-LICENSE +23 -0
  5. data/Rakefile +78 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/micronaut +4 -0
  8. data/examples/example_helper.rb +54 -0
  9. data/examples/lib/micronaut/behaviour_example.rb +351 -0
  10. data/examples/lib/micronaut/configuration_example.rb +133 -0
  11. data/examples/lib/micronaut/example_example.rb +67 -0
  12. data/examples/lib/micronaut/expectations/extensions/object_example.rb +146 -0
  13. data/examples/lib/micronaut/expectations/fail_with_example.rb +17 -0
  14. data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +27 -0
  15. data/examples/lib/micronaut/formatters/base_formatter_example.rb +117 -0
  16. data/examples/lib/micronaut/formatters/documentation_formatter_example.rb +5 -0
  17. data/examples/lib/micronaut/formatters/progress_formatter_example.rb +29 -0
  18. data/examples/lib/micronaut/kernel_extensions_example.rb +13 -0
  19. data/examples/lib/micronaut/matchers/be_close_example.rb +52 -0
  20. data/examples/lib/micronaut/matchers/be_example.rb +298 -0
  21. data/examples/lib/micronaut/matchers/change_example.rb +360 -0
  22. data/examples/lib/micronaut/matchers/description_generation_example.rb +175 -0
  23. data/examples/lib/micronaut/matchers/eql_example.rb +35 -0
  24. data/examples/lib/micronaut/matchers/equal_example.rb +35 -0
  25. data/examples/lib/micronaut/matchers/has_example.rb +69 -0
  26. data/examples/lib/micronaut/matchers/have_example.rb +392 -0
  27. data/examples/lib/micronaut/matchers/include_example.rb +103 -0
  28. data/examples/lib/micronaut/matchers/match_example.rb +43 -0
  29. data/examples/lib/micronaut/matchers/matcher_methods_example.rb +78 -0
  30. data/examples/lib/micronaut/matchers/operator_matcher_example.rb +193 -0
  31. data/examples/lib/micronaut/matchers/raise_error_example.rb +348 -0
  32. data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
  33. data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
  34. data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
  35. data/examples/lib/micronaut/matchers/throw_symbol_example.rb +125 -0
  36. data/examples/lib/micronaut/mocha_example.rb +29 -0
  37. data/examples/lib/micronaut/runner_example.rb +41 -0
  38. data/examples/lib/micronaut/world_example.rb +98 -0
  39. data/examples/lib/micronaut_example.rb +43 -0
  40. data/examples/resources/example_classes.rb +67 -0
  41. data/lib/micronaut.rb +40 -0
  42. data/lib/micronaut/behaviour.rb +217 -0
  43. data/lib/micronaut/configuration.rb +162 -0
  44. data/lib/micronaut/example.rb +112 -0
  45. data/lib/micronaut/expectations.rb +45 -0
  46. data/lib/micronaut/expectations/extensions/object.rb +92 -0
  47. data/lib/micronaut/expectations/handler.rb +51 -0
  48. data/lib/micronaut/expectations/wrap_expectation.rb +52 -0
  49. data/lib/micronaut/formatters.rb +12 -0
  50. data/lib/micronaut/formatters/base_formatter.rb +127 -0
  51. data/lib/micronaut/formatters/base_text_formatter.rb +139 -0
  52. data/lib/micronaut/formatters/documentation_formatter.rb +78 -0
  53. data/lib/micronaut/formatters/progress_formatter.rb +30 -0
  54. data/lib/micronaut/kernel_extensions.rb +11 -0
  55. data/lib/micronaut/matchers.rb +141 -0
  56. data/lib/micronaut/matchers/be.rb +204 -0
  57. data/lib/micronaut/matchers/be_close.rb +37 -0
  58. data/lib/micronaut/matchers/change.rb +148 -0
  59. data/lib/micronaut/matchers/eql.rb +26 -0
  60. data/lib/micronaut/matchers/equal.rb +26 -0
  61. data/lib/micronaut/matchers/generated_descriptions.rb +36 -0
  62. data/lib/micronaut/matchers/has.rb +19 -0
  63. data/lib/micronaut/matchers/have.rb +153 -0
  64. data/lib/micronaut/matchers/include.rb +80 -0
  65. data/lib/micronaut/matchers/match.rb +22 -0
  66. data/lib/micronaut/matchers/method_missing.rb +9 -0
  67. data/lib/micronaut/matchers/operator_matcher.rb +50 -0
  68. data/lib/micronaut/matchers/raise_error.rb +128 -0
  69. data/lib/micronaut/matchers/respond_to.rb +50 -0
  70. data/lib/micronaut/matchers/satisfy.rb +50 -0
  71. data/lib/micronaut/matchers/simple_matcher.rb +135 -0
  72. data/lib/micronaut/matchers/throw_symbol.rb +108 -0
  73. data/lib/micronaut/mocking/with_absolutely_nothing.rb +11 -0
  74. data/lib/micronaut/mocking/with_mocha.rb +15 -0
  75. data/lib/micronaut/mocking/with_rr.rb +24 -0
  76. data/lib/micronaut/rake_task.rb +84 -0
  77. data/lib/micronaut/runner.rb +60 -0
  78. data/lib/micronaut/world.rb +75 -0
  79. metadata +165 -0
@@ -0,0 +1,15 @@
1
+ 0.0.8
2
+ =======================
3
+ - It turns out I'm horrible at updating history files
4
+ - Added MockWith::AbsolutelyNothing as the default
5
+ - Added the ability to setup before, after, include, and extend blocks using a extensible API
6
+
7
+ 0.0.6
8
+ =======================
9
+ - MockWith::Mocha autoloads now
10
+ - Beginnings of the configure block in example helper
11
+ - Ability to search behaviour groups is in
12
+
13
+ 0.0.5
14
+ =======================
15
+ - Describes are working at any level, befores/afters correctly cascade
data/LICENSE ADDED
@@ -0,0 +1,45 @@
1
+ Copyright (c) 2008 Chad Humphries
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+
23
+ The matchers and expectations are licensed:
24
+ (The MIT License)
25
+
26
+ Copyright (c) 2005-2008 The RSpec Development Team
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining
29
+ a copy of this software and associated documentation files (the
30
+ "Software"), to deal in the Software without restriction, including
31
+ without limitation the rights to use, copy, modify, merge, publish,
32
+ distribute, sublicense, and/or sell copies of the Software, and to
33
+ permit persons to whom the Software is furnished to do so, subject to
34
+ the following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be
37
+ included in all copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
40
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
42
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
43
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
44
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # Micronaut
2
+
3
+ * [Codes - http://github.com/spicycode/micronaut](http://github.com/spicycode/micronaut)
4
+ * [Examples - http://runcoderun.com/spicycode/micronaut](http://runcoderun.com/spicycode/micronaut)
5
+ * [Rails - http://github.com/spicycode/micronaut-rails](http://github.com/spicycode/micronaut-rails)
6
+
7
+ ## DESCRIPTION:
8
+
9
+ Micronaut is a light-weight BDD test framework.
10
+
11
+ ## FEATURES:
12
+
13
+ * API compatible with RSpec (of course)
14
+
15
+ * Slim and light, designed to be readable, compact, and fast. Just over ~1600 LOC in /lib at last count.
16
+
17
+ * Each example has its own metadata, and you can add filters or modules to run/disable/enhance examples based on that metadata at run time
18
+ * A Real-world example of the power the metadata gives you:
19
+
20
+ * "Focused examples". Never drop out of Autotest again - just focus on the example(s) and ignore the rest:
21
+
22
+ Micronaut.configure do |c| # in your example_helper
23
+ c.filter_run :focused => true
24
+ end
25
+
26
+ describe Foo do
27
+ it "this example will run", :focused => true do
28
+ end
29
+
30
+ # equivalent to:
31
+ focused "so will this one (this is an alias for :focused => true)" do
32
+ end
33
+
34
+ it "this example will not run, until the focused ones are removed" do
35
+ end
36
+ end
37
+
38
+ * Add your own metadata options and customize Micronaut to your hearts content (pending specs are implemented as ':pending => true' metadata, for example)
39
+
40
+ * Designed to be formatter compatible with RSpec (though this needs some real-world testing)
41
+
42
+ * Rake task for simple setup
43
+
44
+ require 'rubygems'
45
+ require 'micronaut/rake_task'
46
+
47
+ desc "Run all micronaut examples"
48
+ Micronaut::RakeTask.new :examples do |t|
49
+ t.pattern = "examples/**/*_example.rb"
50
+ end
51
+
52
+ desc "Run all micronaut examples using rcov"
53
+ Micronaut::RakeTask.new :coverage do |t|
54
+ t.pattern = "examples/**/*_example.rb"
55
+ t.rcov = true
56
+ t.rcov_opts = "--exclude \"examples/*,gems/*,db/*,/Library/Ruby/*,config/*\" --text-summary --sort coverage --no-validator-links"
57
+ end
58
+ ## REQUIREMENTS:
59
+
60
+ + Ruby 1.8.6+
61
+
62
+ ## CREDITS:
63
+
64
+ * Mini/Unit for the great ideas and runner
65
+ * RSpec for the great ideas, matchers, expectations and formatter ideas
66
+ * Matchers are licensed under the MIT license, per RSpec (see RSPEC-LICENSE)
@@ -0,0 +1,23 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2005-2008 The RSpec Development Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
@@ -0,0 +1,78 @@
1
+ require 'lib/micronaut/rake_task'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "micronaut"
7
+ s.executables = "micronaut"
8
+ s.summary = "An excellent replacement for the wheel..."
9
+ s.email = "chad@spicycode.com"
10
+ s.homepage = "http://github.com/spicycode/micronaut"
11
+ s.description = "An excellent replacement for the wheel..."
12
+ s.authors = ["Chad Humphries"]
13
+ s.files = FileList["[A-Z]*", "{bin,lib,examples}/**/*"]
14
+ s.rubyforge_project = 'spicycode-depot'
15
+ end
16
+ rescue => e
17
+ puts "Jeweler, or one of its dependencies blew right up. #{e}"
18
+ rescue LoadError
19
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
+ end
21
+
22
+ # These are new tasks
23
+ begin
24
+ require 'rake/contrib/sshpublisher'
25
+ namespace :rubyforge do
26
+
27
+ desc "Release gem and RDoc documentation to RubyForge"
28
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
29
+
30
+ namespace :release do
31
+ desc "Publish RDoc to RubyForge."
32
+ task :docs => [:rdoc] do
33
+ config = YAML.load(
34
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
35
+ )
36
+
37
+ host = "#{config['username']}@rubyforge.org"
38
+ remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
39
+ local_dir = 'rdoc'
40
+
41
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
42
+ end
43
+ end
44
+ end
45
+ rescue LoadError
46
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
47
+ end
48
+
49
+
50
+ desc "List files that don't have examples"
51
+ task :untested do
52
+ code = Dir["lib/**/*.rb"].map { |g| Dir.glob(g) }.flatten
53
+ examples = Dir["examples/**/*_example.rb"].map { |g| Dir.glob(g) }.flatten
54
+ examples.map! { |f| f =~ /examples\/(.*)_example/; "#{$1}.rb" }
55
+ puts "\nThe following files seem to be missing their examples:"
56
+ (code - examples).each do |missing|
57
+ puts " #{missing}"
58
+ end
59
+ end
60
+
61
+ puts "Running in Ruby #{RUBY_VERSION}"
62
+ desc "Run all micronaut examples"
63
+ Micronaut::RakeTask.new :examples do |t|
64
+ t.pattern = "examples/**/*_example.rb"
65
+ end
66
+
67
+ namespace :examples do
68
+
69
+ desc "Run all micronaut examples using rcov"
70
+ Micronaut::RakeTask.new :coverage do |t|
71
+ t.pattern = "examples/**/*_example.rb"
72
+ t.rcov = true
73
+ t.rcov_opts = %[--exclude "examples/*,gems/*,db/*,/Library/Ruby/*,config/*" --text-summary --sort coverage]
74
+ end
75
+
76
+ end
77
+
78
+ task :default => 'examples:coverage'
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 9
3
+ :major: 0
4
+ :minor: 2
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
3
+ require 'micronaut'
4
+ Micronaut.configuration.autorun!
@@ -0,0 +1,54 @@
1
+ lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib")
2
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
3
+
4
+ require 'micronaut'
5
+ require 'rubygems'
6
+
7
+ def with_ruby(version)
8
+ yield if RUBY_PLATFORM =~ Regexp.compile("^#{version}")
9
+ end
10
+
11
+ with_ruby("1.8") { gem :mocha }
12
+
13
+ require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes")
14
+
15
+ module Micronaut
16
+ module Matchers
17
+ def fail
18
+ raise_error(::Micronaut::Expectations::ExpectationNotMetError)
19
+ end
20
+
21
+ def fail_with(message)
22
+ raise_error(::Micronaut::Expectations::ExpectationNotMetError, message)
23
+ end
24
+ end
25
+ end
26
+
27
+ def remove_last_describe_from_world
28
+ Micronaut.world.behaviours.pop
29
+ end
30
+
31
+ def isolate_behaviour
32
+ if block_given?
33
+ yield
34
+ Micronaut.world.behaviours.pop
35
+ end
36
+ end
37
+
38
+ def use_formatter(new_formatter)
39
+ original_formatter = Micronaut.configuration.formatter
40
+ Micronaut.configuration.instance_variable_set(:@formatter, new_formatter)
41
+ yield
42
+ ensure
43
+ Micronaut.configuration.instance_variable_set(:@formatter, original_formatter)
44
+ end
45
+
46
+ def not_in_editor?
47
+ !(ENV.has_key?('TM_MODE') || ENV.has_key?('EMACS') || ENV.has_key?('VIM'))
48
+ end
49
+
50
+ Micronaut.configure do |c|
51
+ c.mock_with :mocha
52
+ c.color_enabled = not_in_editor?
53
+ c.filter_run :focused => true
54
+ end
@@ -0,0 +1,351 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../example_helper")
2
+
3
+ describe Micronaut::Behaviour do
4
+
5
+ def empty_behaviour_group
6
+ group = Micronaut::Behaviour.describe(Object, 'Empty Behaviour Group') { }
7
+ remove_last_describe_from_world
8
+ end
9
+
10
+ describe "describing behaviour with #describe" do
11
+
12
+ example "an ArgumentError is raised if no type or description is given" do
13
+ lambda { Micronaut::Behaviour.describe() {} }.should raise_error(ArgumentError, "No arguments given. You must a least supply a type or description")
14
+ end
15
+
16
+ example "an ArgumentError is raised if no block is given" do
17
+ lambda { Micronaut::Behaviour.describe('foo') }.should raise_error(ArgumentError, "You must supply a block when calling describe")
18
+ end
19
+
20
+ describe '#name' do
21
+
22
+ it "should expose the first parameter as name" do
23
+ isolate_behaviour do
24
+ Micronaut::Behaviour.describe("my favorite pony") { }.name.should == 'my favorite pony'
25
+ end
26
+ end
27
+
28
+ it "should call to_s on the first parameter in case it is a constant" do
29
+ isolate_behaviour do
30
+ Micronaut::Behaviour.describe(Object) { }.name.should == 'Object'
31
+ end
32
+ end
33
+
34
+ pending "should build a nested name correctly, including the module, and each nested description in the correct order" do
35
+ behaviour_to_test = nil
36
+
37
+ isolate_behaviour do
38
+ Micronaut::Behaviour.describe(Micronaut, "test") do
39
+ Micronaut::Behaviour.describe("nested one") do
40
+ behaviour_to_test = Micronaut::Behaviour.describe("nested two") { }
41
+ end
42
+ end
43
+ end
44
+
45
+ behaviour_to_test.name.should == 'Micronaut - test - nested one - nested two'
46
+ end
47
+
48
+ end
49
+
50
+ describe '#describes' do
51
+
52
+ it "should be the first parameter when it is a constant" do
53
+ isolate_behaviour do
54
+ Micronaut::Behaviour.describe(Object) { }.describes.should == Object
55
+ end
56
+ end
57
+
58
+ it "should be nil when the first parameter is a string" do
59
+ isolate_behaviour do
60
+ Micronaut::Behaviour.describe("i'm a computer") { }.describes.should be_nil
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ describe '#description' do
67
+
68
+ it "should expose the second parameter as description" do
69
+ isolate_behaviour do
70
+ Micronaut::Behaviour.describe(Object, "my desc") { }.description.should == 'my desc'
71
+ end
72
+ end
73
+
74
+ it "should allow the second parameter to be nil" do
75
+ isolate_behaviour do
76
+ Micronaut::Behaviour.describe(Object, nil) { }.description.size.should == 0
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ describe '#metadata' do
83
+
84
+ it "should add the third parameter to the metadata" do
85
+ isolate_behaviour do
86
+ Micronaut::Behaviour.describe(Object, nil, 'foo' => 'bar') { }.metadata.should include({ "foo" => 'bar' })
87
+ end
88
+ end
89
+
90
+ it "should add the caller to metadata" do
91
+ isolate_behaviour do
92
+ Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:caller][4].should =~ /#{__FILE__}:#{__LINE__}/
93
+ end
94
+ end
95
+
96
+ it "should add the the file_path to metadata" do
97
+ isolate_behaviour do
98
+ Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
99
+ end
100
+ end
101
+
102
+ it "should have a reader for file_path" do
103
+ isolate_behaviour do
104
+ Micronaut::Behaviour.describe(Object) { }.file_path.should == __FILE__
105
+ end
106
+ end
107
+
108
+ it "should add the line_number to metadata" do
109
+ isolate_behaviour do
110
+ Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
111
+ end
112
+ end
113
+
114
+ it "should add file path and line number metadata for arbitrarily nested describes" do
115
+ Micronaut::Behaviour.describe(Object) do
116
+ Micronaut::Behaviour.describe("foo") do
117
+ Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:file_path].should == __FILE__
118
+ Micronaut::Behaviour.describe(Object) { }.metadata[:behaviour][:line_number].should == __LINE__
119
+ end
120
+ end
121
+
122
+ 4.times { remove_last_describe_from_world }
123
+ end
124
+
125
+ end
126
+
127
+ describe "adding before and after hooks" do
128
+
129
+ it "should expose the before each blocks at before_eachs" do
130
+ group = empty_behaviour_group
131
+ group.before(:each) { 'foo' }
132
+ group.should have(1).before_eachs
133
+ end
134
+
135
+ it "should maintain the before each block order" do
136
+ group = empty_behaviour_group
137
+ group.before(:each) { 15 }
138
+ group.before(:each) { 'A' }
139
+ group.before(:each) { 33.5 }
140
+
141
+ group.before_eachs[0].call.should == 15
142
+ group.before_eachs[1].call.should == 'A'
143
+ group.before_eachs[2].call.should == 33.5
144
+ end
145
+
146
+ it "should expose the before all blocks at before_alls" do
147
+ group = empty_behaviour_group
148
+ group.before(:all) { 'foo' }
149
+ group.should have(1).before_alls
150
+ end
151
+
152
+ it "should maintain the before all block order" do
153
+ group = empty_behaviour_group
154
+ group.before(:all) { 15 }
155
+ group.before(:all) { 'A' }
156
+ group.before(:all) { 33.5 }
157
+
158
+ group.before_alls[0].call.should == 15
159
+ group.before_alls[1].call.should == 'A'
160
+ group.before_alls[2].call.should == 33.5
161
+ end
162
+
163
+ it "should expose the after each blocks at after_eachs" do
164
+ group = empty_behaviour_group
165
+ group.after(:each) { 'foo' }
166
+ group.should have(1).after_eachs
167
+ end
168
+
169
+ it "should maintain the after each block order" do
170
+ group = empty_behaviour_group
171
+ group.after(:each) { 15 }
172
+ group.after(:each) { 'A' }
173
+ group.after(:each) { 33.5 }
174
+
175
+ group.after_eachs[0].call.should == 15
176
+ group.after_eachs[1].call.should == 'A'
177
+ group.after_eachs[2].call.should == 33.5
178
+ end
179
+
180
+ it "should expose the after all blocks at after_alls" do
181
+ group = empty_behaviour_group
182
+ group.after(:all) { 'foo' }
183
+ group.should have(1).after_alls
184
+ end
185
+
186
+ it "should maintain the after each block order" do
187
+ group = empty_behaviour_group
188
+ group.after(:all) { 15 }
189
+ group.after(:all) { 'A' }
190
+ group.after(:all) { 33.5 }
191
+
192
+ group.after_alls[0].call.should == 15
193
+ group.after_alls[1].call.should == 'A'
194
+ group.after_alls[2].call.should == 33.5
195
+ end
196
+
197
+ end
198
+
199
+ describe "adding examples" do
200
+
201
+ it "should allow adding an example using 'it'" do
202
+ group = empty_behaviour_group
203
+ group.it("should do something") { }
204
+ group.examples.size.should == 1
205
+ end
206
+
207
+ it "should expose all examples at examples" do
208
+ group = empty_behaviour_group
209
+ group.it("should do something 1") { }
210
+ group.it("should do something 2") { }
211
+ group.it("should do something 3") { }
212
+ group.examples.size.should == 3
213
+ end
214
+
215
+ it "should maintain the example order" do
216
+ group = empty_behaviour_group
217
+ group.it("should 1") { }
218
+ group.it("should 2") { }
219
+ group.it("should 3") { }
220
+ group.examples[0].description.should == 'should 1'
221
+ group.examples[1].description.should == 'should 2'
222
+ group.examples[2].description.should == 'should 3'
223
+ end
224
+
225
+ end
226
+
227
+ end
228
+
229
+ describe Object, "describing nested behaviours", :little_less_nested => 'yep' do
230
+
231
+ describe "A sample nested describe", :nested_describe => "yep" do
232
+
233
+ it "should set the described type to the constant Object" do
234
+ running_example.behaviour.describes.should == Object
235
+ end
236
+
237
+ it "should set the description to 'A sample nested describe'" do
238
+ running_example.behaviour.description.should == 'A sample nested describe'
239
+ end
240
+
241
+ it "should have top level metadata from the behaviour and its ancestors" do
242
+ running_example.behaviour.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
243
+ end
244
+
245
+ it "should make the parent metadata available on the contained examples" do
246
+ running_example.metadata.should include(:little_less_nested => 'yep', :nested_describe => 'yep')
247
+ end
248
+
249
+ end
250
+
251
+ end
252
+
253
+ describe "#run_examples" do
254
+
255
+ before do
256
+ @fake_formatter = Micronaut::Formatters::BaseFormatter.new
257
+ end
258
+
259
+ def stub_behaviour
260
+ stub_everything('behaviour', :metadata => { :behaviour => { :name => 'behaviour_name' }})
261
+ end
262
+
263
+ it "should return true if all examples pass" do
264
+ use_formatter(@fake_formatter) do
265
+ passing_example1 = Micronaut::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
266
+ passing_example2 = Micronaut::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
267
+ Micronaut::Behaviour.stubs(:examples_to_run).returns([passing_example1, passing_example2])
268
+
269
+ Micronaut::Behaviour.run_examples(stub_behaviour, stub_everything('reporter')).should be_true
270
+ end
271
+ end
272
+
273
+ it "should return false if any of the examples return false" do
274
+ use_formatter(@fake_formatter) do
275
+ failing_example = Micronaut::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 }))
276
+ passing_example = Micronaut::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
277
+ Micronaut::Behaviour.stubs(:examples_to_run).returns([failing_example, passing_example])
278
+
279
+ Micronaut::Behaviour.run_examples(stub_behaviour, stub_everything('reporter')).should be_false
280
+ end
281
+ end
282
+
283
+ it "should run all examples, regardless of any of them failing" do
284
+ use_formatter(@fake_formatter) do
285
+ failing_example = Micronaut::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 2 }))
286
+ passing_example = Micronaut::Example.new(stub_behaviour, 'description', {}, (lambda { 1.should == 1 }))
287
+ Micronaut::Behaviour.stubs(:examples_to_run).returns([failing_example, passing_example])
288
+
289
+ passing_example.expects(:run)
290
+
291
+ Micronaut::Behaviour.run_examples(stub_behaviour, stub_everything('reporter'))
292
+ end
293
+ end
294
+
295
+ end
296
+
297
+ describe "how instance variables inherit" do
298
+
299
+ before(:all) do
300
+ @before_all_top_level = 'before_all_top_level'
301
+ end
302
+
303
+ before(:each) do
304
+ @before_each_top_level = 'before_each_top_level'
305
+ end
306
+
307
+ it "should be able to access a before each ivar at the same level" do
308
+ @before_each_top_level.should == 'before_each_top_level'
309
+ end
310
+
311
+ it "should be able to access a before all ivar at the same level" do
312
+ @before_all_top_level.should == 'before_all_top_level'
313
+ end
314
+
315
+
316
+ it "should be able to access the before all ivars in the before_all_ivars hash" do
317
+ with_ruby('1.8') do
318
+ running_example.behaviour.before_all_ivars.should include('@before_all_top_level' => 'before_all_top_level')
319
+ end
320
+ with_ruby('1.9') do
321
+ running_example.behaviour.before_all_ivars.should include(:@before_all_top_level => 'before_all_top_level')
322
+ end
323
+ end
324
+
325
+ describe "but now I am nested" do
326
+
327
+ it "should be able to access a parent behaviours before each ivar at a nested level" do
328
+ @before_each_top_level.should == 'before_each_top_level'
329
+ end
330
+
331
+ it "should be able to access a parent behaviours before all ivar at a nested level" do
332
+ @before_all_top_level.should == "before_all_top_level"
333
+ end
334
+
335
+ it "changes to before all ivars from within an example do not persist outside the current describe" do
336
+ @before_all_top_level = "ive been changed"
337
+ end
338
+
339
+ describe "accessing a before_all ivar that was changed in a parent behaviour" do
340
+
341
+ it "should have access to the modified version" do
342
+ @before_all_top_level.should == 'ive been changed'
343
+ end
344
+
345
+ end
346
+
347
+ end
348
+
349
+ end
350
+
351
+ end