dchelimsky-rspec 1.1.11.4 → 1.1.11.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/History.txt +4 -2
  2. data/Manifest.txt +7 -3
  3. data/Rakefile +1 -1
  4. data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +86 -0
  5. data/features/before_and_after_blocks/before_and_after_blocks.feature +168 -0
  6. data/features/step_definitions/running_rspec.rb +7 -1
  7. data/lib/spec.rb +1 -0
  8. data/lib/spec/dsl/main.rb +2 -1
  9. data/lib/spec/example/before_and_after_hooks.rb +20 -2
  10. data/lib/spec/example/example_group_factory.rb +11 -0
  11. data/lib/spec/example/example_group_methods.rb +32 -35
  12. data/lib/spec/example/shared_example_group.rb +0 -4
  13. data/lib/spec/matchers/respond_to.rb +1 -2
  14. data/lib/spec/matchers/wrap_expectation.rb +1 -1
  15. data/lib/spec/mocks/proxy.rb +1 -1
  16. data/lib/spec/ruby.rb +9 -0
  17. data/lib/spec/runner/configuration.rb +6 -7
  18. data/lib/spec/runner/formatter/nested_text_formatter.rb +2 -2
  19. data/lib/spec/runner/heckle_runner.rb +58 -56
  20. data/lib/spec/runner/options.rb +9 -4
  21. data/lib/spec/version.rb +1 -1
  22. data/rspec.gemspec +5 -5
  23. data/spec/spec/dsl/main_spec.rb +21 -1
  24. data/spec/spec/example/example_group_methods_spec.rb +51 -0
  25. data/spec/spec/example/example_methods_spec.rb +1 -33
  26. data/spec/spec/matchers/have_spec.rb +2 -2
  27. data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
  28. data/spec/spec/mocks/stub_spec.rb +6 -0
  29. data/spec/spec/runner/configuration_spec.rb +11 -0
  30. data/spec/spec/runner/drb_command_line_spec.rb +4 -4
  31. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +1 -0
  32. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +5 -5
  33. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +3 -3
  34. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +24 -24
  35. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +379 -0
  36. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +379 -0
  37. data/spec/spec/runner/formatter/html_formatter_spec.rb +9 -13
  38. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +4 -4
  39. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +3 -3
  40. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +8 -12
  41. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +4 -4
  42. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +18 -18
  43. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +373 -0
  44. data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +373 -0
  45. data/spec/spec/runner/heckler_spec.rb +16 -9
  46. data/spec/spec/runner/option_parser_spec.rb +0 -2
  47. data/spec/spec/runner/options_spec.rb +7 -2
  48. data/spec/spec/runner/reporter_spec.rb +4 -4
  49. data/spec/spec_helper.rb +4 -0
  50. metadata +10 -6
  51. data/features/configuration/before_blocks.feature +0 -21
  52. data/resources/spec/before_blocks_example.rb +0 -32
  53. data/spec/spec/example/example_runner_spec.rb +0 -194
data/History.txt CHANGED
@@ -14,7 +14,7 @@
14
14
  * hash_including mock argument matcher can now accept just keys, key/value pairs, or both (David Krmpotic)
15
15
  * added hash_not_including mock argument matcher (David Krmpotic). Closes #634.
16
16
 
17
- * 6 minor enhancements
17
+ * 7 minor enhancements
18
18
 
19
19
  * should throw_symbol accepts an optional argument: should throw_symbol(:sym, arg)
20
20
  * fixed --line for jruby (Zach Moazeni)
@@ -22,8 +22,9 @@
22
22
  * removed all instances of class << self - I do know who I am
23
23
  * SpecParser can't handle backtrace paths with colons (John-Mason P. Shackelford). Closes #505.
24
24
  * html formatter (and subsequently the textmate formatter) header fills in completely when running a single example
25
+ * config.include now accepts an array of types (config.include(Helpers, :type => [:view, :controller]))
25
26
 
26
- * 8 bug fixes
27
+ * 9 bug fixes
27
28
 
28
29
  * fixed bug where {:a => 1, :b => 2}.should include(:a, :b) failed (Yossef Mendelssohn)
29
30
  * only try to load Test::Unit if Test::Unit is defined (not just Test)
@@ -33,6 +34,7 @@
33
34
  * Check whether test/unit has really been loaded before calling a method it defines (Brian Donovan). Closes #503.
34
35
  * Fix spec_path for shared groups (Zach Dennis). Closes #615.
35
36
  * stubbed message expectation not verified if it has been called *before* the expectation (Matthias Hennemeyer). Closes #637.
37
+ * stubs calculate return value by executing block passed to #and_return (hint from Aisha Fenton). Closes #642.
36
38
 
37
39
  === Version 1.1.11 / 2008-10-24
38
40
 
data/Manifest.txt CHANGED
@@ -52,7 +52,8 @@ examples/passing/stack_spec.rb
52
52
  examples/passing/stack_spec_with_nested_example_groups.rb
53
53
  examples/passing/stubbing_example.rb
54
54
  examples/passing/yielding_example.rb
55
- features/configuration/before_blocks.feature
55
+ examples/ruby1.9.compatibility/access_to_constants_spec.rb
56
+ features/before_and_after_blocks/before_and_after_blocks.feature
56
57
  features/example_groups/autogenerated_docstrings.feature
57
58
  features/example_groups/example_group_with_should_methods.feature
58
59
  features/example_groups/nested_groups.feature
@@ -139,6 +140,7 @@ lib/spec/mocks/space.rb
139
140
  lib/spec/mocks/spec_methods.rb
140
141
  lib/spec/rake/spectask.rb
141
142
  lib/spec/rake/verify_rcov.rb
143
+ lib/spec/ruby.rb
142
144
  lib/spec/runner.rb
143
145
  lib/spec/runner/backtrace_tweaker.rb
144
146
  lib/spec/runner/class_and_arguments_parser.rb
@@ -190,7 +192,6 @@ resources/rake/examples.rake
190
192
  resources/rake/examples_with_rcov.rake
191
193
  resources/rake/failing_examples_with_html.rake
192
194
  resources/rake/verify_rcov.rake
193
- resources/spec/before_blocks_example.rb
194
195
  resources/spec/example_group_with_should_methods.rb
195
196
  resources/spec/simple_spec.rb
196
197
  resources/spec/spec_with_flexmock.rb
@@ -214,7 +215,6 @@ spec/spec/example/example_group_methods_spec.rb
214
215
  spec/spec/example/example_group_spec.rb
215
216
  spec/spec/example/example_matcher_spec.rb
216
217
  spec/spec/example/example_methods_spec.rb
217
- spec/spec/example/example_runner_spec.rb
218
218
  spec/spec/example/helper_method_spec.rb
219
219
  spec/spec/example/nested_example_group_spec.rb
220
220
  spec/spec/example/pending_module_spec.rb
@@ -308,6 +308,8 @@ spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html
308
308
  spec/spec/runner/formatter/html_formatted-1.8.5.html
309
309
  spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html
310
310
  spec/spec/runner/formatter/html_formatted-1.8.6.html
311
+ spec/spec/runner/formatter/html_formatted-1.8.7.html
312
+ spec/spec/runner/formatter/html_formatted-1.9.1.html
311
313
  spec/spec/runner/formatter/html_formatter_spec.rb
312
314
  spec/spec/runner/formatter/nested_text_formatter_spec.rb
313
315
  spec/spec/runner/formatter/profile_formatter_spec.rb
@@ -320,6 +322,8 @@ spec/spec/runner/formatter/story/plain_text_formatter_spec.rb
320
322
  spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb
321
323
  spec/spec/runner/formatter/text_mate_formatted-1.8.4.html
322
324
  spec/spec/runner/formatter/text_mate_formatted-1.8.6.html
325
+ spec/spec/runner/formatter/text_mate_formatted-1.8.7.html
326
+ spec/spec/runner/formatter/text_mate_formatted-1.9.1.html
323
327
  spec/spec/runner/heckle_runner_spec.rb
324
328
  spec/spec/runner/heckler_spec.rb
325
329
  spec/spec/runner/noisy_backtrace_tweaker_spec.rb
data/Rakefile CHANGED
@@ -44,7 +44,7 @@ Spec::Rake::SpecTask.new do |t|
44
44
  unless ENV['NO_RCOV']
45
45
  t.rcov = true
46
46
  t.rcov_dir = 'coverage'
47
- t.rcov_opts = ['--text-report', '--exclude', "lib/spec.rb,lib/spec/runner.rb,spec\/spec,bin\/spec,examples,\/var\/lib\/gems,\/Library\/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
47
+ t.rcov_opts = ['--text-report', '--exclude', "lib/spec.rb,lib/spec/runner.rb,spec\/spec,bin\/spec,examples,\/gems,\/Library\/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
48
48
  end
49
49
  end
50
50
 
@@ -0,0 +1,86 @@
1
+ # courtesy of Matthias Hennemeyer
2
+ #
3
+ # The following should pass against ruby 1.8 and 1.9. It currently only passes
4
+ # 1.8 (as of 1/2/2009)
5
+ #
6
+ # Once cucumber supports ruby 1.9, this should be moved to cucumber scenarios instead.
7
+ module Foo
8
+ module Bar
9
+
10
+ module ModuleInEnclosingModule;end
11
+ class ClassInEnclosingModule;end
12
+ def method_in_enclosing_module;end
13
+ CONSTANT_IN_ENCLOSING_MODULE = 0
14
+
15
+ describe "Examples trying to access constants defined in an enclosing module" do
16
+
17
+ it "can access Modules" do
18
+ ModuleInEnclosingModule
19
+ end
20
+ it "can access Classes" do
21
+ ClassInEnclosingModule.new
22
+ end
23
+ it "can access CONSTANTS" do
24
+ CONSTANT_IN_ENCLOSING_MODULE
25
+ end
26
+ it "can NOT access methods" do
27
+ lambda {method_in_enclosing_module}.should raise_error(/undefined/)
28
+ end
29
+
30
+ describe "from a nested example group" do
31
+
32
+ it "can access Modules" do
33
+ ModuleInEnclosingModule
34
+ end
35
+ it "can access Classes" do
36
+ ClassInEnclosingModule.new
37
+ end
38
+ it "can access CONSTANTS" do
39
+ CONSTANT_IN_ENCLOSING_MODULE
40
+ end
41
+ it "can NOT access methods" do
42
+ lambda {method_in_enclosing_module}.should raise_error(/undefined/)
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ describe "Examples trying to access constants defined in the example group" do
50
+
51
+ module ModuleDefinedInGroup;end
52
+ class ClassDefinedInGroup; end
53
+ def method_defined_in_group; end
54
+ CONSTANT_DEFINED_IN_GROUP = 0
55
+
56
+ it "can access Modules" do
57
+ ModuleDefinedInGroup
58
+ end
59
+ it "can access Classes" do
60
+ ClassDefinedInGroup.new
61
+ end
62
+ it "can access CONSTANTS" do
63
+ CONSTANT_DEFINED_IN_GROUP
64
+ end
65
+ it "can access methods" do
66
+ method_defined_in_group
67
+ end
68
+
69
+ describe "that live inside a nested group" do
70
+ it "can access Modules" do
71
+ ModuleDefinedInGroup
72
+ end
73
+ it "can access Classes" do
74
+ ClassDefinedInGroup.new
75
+ end
76
+ it "can access CONSTANTS" do
77
+ CONSTANT_DEFINED_IN_GROUP
78
+ end
79
+ it "can access methods" do
80
+ method_defined_in_group
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
@@ -0,0 +1,168 @@
1
+ Feature: before and after blocks
2
+
3
+ As a developer using RSpec
4
+ I want to execute arbitrary code before and after each example
5
+ So that I can control the environment in which it is run
6
+
7
+ This is supported by the before and after methods which each take a symbol
8
+ indicating the scope, and a block of code to execute.
9
+
10
+ before(:each) blocks are run before each example
11
+ before(:all) blocks are run once before all of the examples in a group
12
+ before(:suite) blocks are run once before the entire suite
13
+
14
+ after(:each) blocks are run after each example
15
+ after(:all) blocks are run once after all of the examples in a group
16
+ after(:suite) blocks are run once after the entire suite
17
+
18
+ Before and after blocks are called in the following order:
19
+ before suite
20
+ before all
21
+ before each
22
+ after each
23
+ after all
24
+ after suite
25
+
26
+ Before and after blocks can be defined in the example groups to which they
27
+ apply or in a configuration. When defined in a configuration, they can be
28
+ applied to all groups or subsets of all groups defined by example group
29
+ types.
30
+
31
+ Scenario: define before(:each) block in example group
32
+ Given the following spec:
33
+ """
34
+ class Thing
35
+ def widgets
36
+ @widgets ||= []
37
+ end
38
+ end
39
+
40
+ describe Thing do
41
+ before(:each) do
42
+ @thing = Thing.new
43
+ end
44
+
45
+ context "initialized in before(:each)" do
46
+ it "has 0 widgets" do
47
+ @thing.should have(0).widgets
48
+ end
49
+
50
+ it "can get accept new widgets" do
51
+ @thing.widgets << Object.new
52
+ end
53
+
54
+ it "does not share state across examples" do
55
+ @thing.should have(0).widgets
56
+ end
57
+ end
58
+ end
59
+ """
60
+ When I run it with the spec script
61
+ Then the stdout should match "3 examples, 0 failures"
62
+
63
+ Scenario: define before(:all) block in example group
64
+ Given the following spec:
65
+ """
66
+ class Thing
67
+ def widgets
68
+ @widgets ||= []
69
+ end
70
+ end
71
+
72
+ describe Thing do
73
+ before(:all) do
74
+ @thing = Thing.new
75
+ end
76
+
77
+ context "initialized in before(:all)" do
78
+ it "has 0 widgets" do
79
+ @thing.should have(0).widgets
80
+ end
81
+
82
+ it "can get accept new widgets" do
83
+ @thing.widgets << Object.new
84
+ end
85
+
86
+ it "shares state across examples" do
87
+ @thing.should have(1).widgets
88
+ end
89
+ end
90
+ end
91
+ """
92
+ When I run it with the spec script
93
+ Then the stdout should match "3 examples, 0 failures"
94
+
95
+ Scenario: define before and after blocks in configuration
96
+ Given the following spec:
97
+ """
98
+ Spec::Runner.configure do |config|
99
+ config.before(:suite) do
100
+ $before_suite = "before suite"
101
+ end
102
+ config.before(:each) do
103
+ @before_each = "before each"
104
+ end
105
+ config.before(:all) do
106
+ @before_all = "before all"
107
+ end
108
+ end
109
+
110
+ describe "stuff in before blocks" do
111
+ describe "with :suite" do
112
+ it "should be available in the example" do
113
+ $before_suite.should == "before suite"
114
+ end
115
+ end
116
+ describe "with :all" do
117
+ it "should be available in the example" do
118
+ @before_all.should == "before all"
119
+ end
120
+ end
121
+ describe "with :each" do
122
+ it "should be available in the example" do
123
+ @before_each.should == "before each"
124
+ end
125
+ end
126
+ end
127
+ """
128
+ When I run it with the spec script
129
+ Then the stdout should match "3 examples, 0 failures"
130
+
131
+ Scenario: before/after blocks are run in order
132
+ Given the following spec:
133
+ """
134
+ Spec::Runner.configure do |config|
135
+ config.before(:suite) do
136
+ puts "before suite"
137
+ end
138
+ config.after(:suite) do
139
+ puts "after suite"
140
+ end
141
+ end
142
+
143
+ describe "before and after callbacks" do
144
+ before(:all) do
145
+ puts "before all"
146
+ end
147
+
148
+ before(:each) do
149
+ puts "before each"
150
+ end
151
+
152
+ after(:each) do
153
+ puts "after each"
154
+ end
155
+
156
+ after(:all) do
157
+ puts "after all"
158
+ end
159
+
160
+ it "gets run in order" do
161
+
162
+ end
163
+ end
164
+ """
165
+
166
+ When I run it with the spec script
167
+ Then the stdout should match /before suite\nbefore all\nbefore each\nafter each\n\.after all\n.*after suite/m
168
+
@@ -5,6 +5,13 @@ Given /^the file (.*)$/ do |relative_path|
5
5
  end
6
6
  end
7
7
 
8
+ Given /^the following spec:$/ do |spec|
9
+ @path = "/tmp/example_spec.rb"
10
+ File.open(@path, "w") do |f|
11
+ f.write spec
12
+ end
13
+ end
14
+
8
15
  When /^I run it with the (.*)$/ do |interpreter|
9
16
  stderr_file = Tempfile.new('rspec')
10
17
  stderr_file.close
@@ -40,7 +47,6 @@ Then /^the (.*) should not match (.*)$/ do |stream, string_or_regex|
40
47
  written.should_not smart_match(string_or_regex)
41
48
  end
42
49
 
43
-
44
50
  Then /^the exit code should be (\d+)$/ do |exit_code|
45
51
  if @exit_code != exit_code.to_i
46
52
  raise "Did not exit with #{exit_code}, but with #{@exit_code}. Standard error:\n#{@stderr}"
data/lib/spec.rb CHANGED
@@ -4,3 +4,4 @@ require 'spec/example'
4
4
  require 'spec/runner'
5
5
  require 'spec/version'
6
6
  require 'spec/dsl'
7
+ require 'spec/ruby'
data/lib/spec/dsl/main.rb CHANGED
@@ -21,10 +21,11 @@ module Spec
21
21
  #
22
22
  def describe(*args, &block)
23
23
  Spec::Example::add_spec_path_to(args)
24
+ Spec::Example::ExampleGroupFactory.assign_scope(self, args)
24
25
  Spec::Example::ExampleGroupFactory.create_example_group(*args, &block)
25
26
  end
26
27
  alias :context :describe
27
-
28
+
28
29
  # Creates an example group that can be shared by other example groups
29
30
  #
30
31
  # == Examples
@@ -1,6 +1,16 @@
1
1
  module Spec
2
2
  module Example
3
3
  module BeforeAndAfterHooks
4
+ class << self
5
+ def before_suite_parts
6
+ @before_suite_parts ||= []
7
+ end
8
+
9
+ def after_suite_parts
10
+ @after_suite_parts ||= []
11
+ end
12
+ end
13
+
4
14
  # Registers a block to be executed before each example.
5
15
  # This method prepends +block+ to existing before blocks.
6
16
  def prepend_before(*args, &block)
@@ -58,13 +68,21 @@ module Spec
58
68
  @after_each_parts ||= []
59
69
  end
60
70
 
71
+ def before_suite_parts
72
+ BeforeAndAfterHooks.before_suite_parts
73
+ end
74
+
75
+ def after_suite_parts
76
+ BeforeAndAfterHooks.after_suite_parts
77
+ end
78
+
61
79
  private
62
80
 
63
81
  def before_parts(*args)
64
82
  case Spec::Example.scope_from(*args)
65
83
  when :each; before_each_parts
66
84
  when :all; before_all_parts
67
- when :suite; Spec::Runner.options.before_suite_parts
85
+ when :suite; before_suite_parts
68
86
  end
69
87
  end
70
88
 
@@ -72,7 +90,7 @@ module Spec
72
90
  case Spec::Example.scope_from(*args)
73
91
  when :each; after_each_parts
74
92
  when :all; after_all_parts
75
- when :suite; Spec::Runner.options.after_suite_parts
93
+ when :suite; after_suite_parts
76
94
  end
77
95
  end
78
96
 
@@ -62,6 +62,17 @@ module Spec
62
62
  SharedExampleGroup.register(*args, &block)
63
63
  end
64
64
 
65
+ def include_constants_in(context, &block)
66
+ if (Spec::Ruby.version.to_f >= 1.9 && Module === context && !(Class === context))
67
+ return lambda {include context;instance_eval(&block)}
68
+ end
69
+ block
70
+ end
71
+
72
+ def assign_scope(scope, args)
73
+ args.last[:scope] = scope
74
+ end
75
+
65
76
  protected
66
77
 
67
78
  def determine_superclass(opts)