rspec 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/CHANGES +35 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README +9 -44
  4. data/Rakefile +34 -51
  5. data/TODO +0 -1
  6. data/UPGRADE +0 -24
  7. data/bin/spec +0 -0
  8. data/bin/spec_translator +0 -0
  9. data/examples/pure/behave_as_example.rb +0 -0
  10. data/examples/pure/partial_mock_example.rb +1 -0
  11. data/examples/stories/calculator.rb +1 -1
  12. data/lib/autotest/rspec.rb +7 -9
  13. data/lib/spec/example.rb +1 -1
  14. data/lib/spec/example/configuration.rb +30 -16
  15. data/lib/spec/example/example_group.rb +2 -1
  16. data/lib/spec/example/example_group_factory.rb +23 -21
  17. data/lib/spec/example/example_group_methods.rb +18 -5
  18. data/lib/spec/example/example_matcher.rb +0 -0
  19. data/lib/spec/example/example_methods.rb +6 -0
  20. data/lib/spec/example/module_inclusion_warnings.rb +37 -0
  21. data/lib/spec/expectations/differs/default.rb +1 -1
  22. data/lib/spec/expectations/extensions/object.rb +4 -12
  23. data/lib/spec/expectations/handler.rb +8 -0
  24. data/lib/spec/extensions.rb +1 -0
  25. data/lib/spec/extensions/metaclass.rb +7 -0
  26. data/lib/spec/extensions/object.rb +0 -4
  27. data/lib/spec/matchers/change.rb +1 -1
  28. data/lib/spec/matchers/has.rb +1 -11
  29. data/lib/spec/matchers/operator_matcher.rb +0 -0
  30. data/lib/spec/matchers/raise_error.rb +53 -30
  31. data/lib/spec/mocks.rb +1 -1
  32. data/lib/spec/mocks/argument_constraint_matchers.rb +5 -1
  33. data/lib/spec/mocks/argument_expectation.rb +26 -0
  34. data/lib/spec/mocks/extensions.rb +1 -0
  35. data/lib/spec/mocks/framework.rb +15 -0
  36. data/lib/spec/mocks/message_expectation.rb +29 -5
  37. data/lib/spec/mocks/mock.rb +9 -7
  38. data/lib/spec/mocks/proxy.rb +26 -12
  39. data/lib/spec/rake/spectask.rb +5 -5
  40. data/lib/spec/runner/backtrace_tweaker.rb +1 -1
  41. data/lib/spec/runner/formatter/base_formatter.rb +2 -3
  42. data/lib/spec/runner/formatter/base_text_formatter.rb +2 -2
  43. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +4 -8
  44. data/lib/spec/runner/formatter/html_formatter.rb +18 -14
  45. data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
  46. data/lib/spec/runner/formatter/profile_formatter.rb +4 -0
  47. data/lib/spec/runner/formatter/progress_bar_formatter.rb +5 -1
  48. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
  49. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +18 -7
  50. data/lib/spec/runner/option_parser.rb +17 -15
  51. data/lib/spec/runner/options.rb +37 -14
  52. data/lib/spec/runner/reporter.rb +15 -11
  53. data/lib/spec/story/extensions/regexp.rb +2 -2
  54. data/lib/spec/story/extensions/string.rb +2 -2
  55. data/lib/spec/story/runner.rb +9 -5
  56. data/lib/spec/story/runner/plain_text_story_runner.rb +2 -2
  57. data/lib/spec/story/runner/scenario_runner.rb +8 -0
  58. data/lib/spec/story/runner/story_mediator.rb +1 -1
  59. data/lib/spec/story/runner/story_runner.rb +3 -1
  60. data/lib/spec/story/step.rb +4 -4
  61. data/lib/spec/story/story.rb +8 -11
  62. data/lib/spec/story/world.rb +0 -1
  63. data/lib/spec/version.rb +2 -2
  64. data/plugins/mock_frameworks/rspec.rb +2 -0
  65. data/spec/autotest/rspec_spec.rb +12 -10
  66. data/spec/spec/example/configuration_spec.rb +0 -0
  67. data/spec/spec/example/example_group/described_module_spec.rb +20 -0
  68. data/spec/spec/example/example_group/warning_messages_spec.rb +76 -0
  69. data/spec/spec/example/example_group_factory_spec.rb +117 -102
  70. data/spec/spec/example/example_group_methods_spec.rb +51 -17
  71. data/spec/spec/example/example_group_spec.rb +13 -1
  72. data/spec/spec/example/example_methods_spec.rb +28 -6
  73. data/spec/spec/example/nested_example_group_spec.rb +12 -0
  74. data/spec/spec/example/predicate_matcher_spec.rb +0 -0
  75. data/spec/spec/expectations/differs/default_spec.rb +27 -9
  76. data/spec/spec/matchers/be_spec.rb +24 -0
  77. data/spec/spec/matchers/has_spec.rb +16 -0
  78. data/spec/spec/matchers/raise_error_spec.rb +124 -0
  79. data/spec/spec/mocks/{bug_report_10263.rb → bug_report_10263_spec.rb} +0 -0
  80. data/spec/spec/mocks/bug_report_11545_spec.rb +2 -0
  81. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +8 -0
  82. data/spec/spec/mocks/hash_including_matcher_spec.rb +32 -0
  83. data/spec/spec/mocks/mock_spec.rb +56 -37
  84. data/spec/spec/mocks/partial_mock_spec.rb +41 -5
  85. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +6 -0
  86. data/spec/spec/runner/execution_context_spec.rb +7 -1
  87. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +3 -2
  88. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +30 -25
  89. data/spec/spec/runner/formatter/html_formatter_spec.rb +0 -3
  90. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +333 -0
  91. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +12 -2
  92. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -2
  93. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -78
  94. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +105 -1
  95. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -28
  96. data/spec/spec/runner/option_parser_spec.rb +65 -49
  97. data/spec/spec/runner/options_spec.rb +103 -17
  98. data/spec/spec/runner/reporter_spec.rb +10 -7
  99. data/spec/spec/runner/spec_drb.opts +1 -0
  100. data/spec/spec/runner/spec_parser_spec.rb +10 -4
  101. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +14 -13
  102. data/spec/spec/story/runner/scenario_runner_spec.rb +124 -52
  103. data/spec/spec/story/runner/story_mediator_spec.rb +2 -2
  104. data/spec/spec/story/runner/story_runner_spec.rb +40 -2
  105. data/spec/spec/story/runner_spec.rb +59 -72
  106. data/spec/spec/story/step_spec.rb +20 -1
  107. data/spec/spec/story/story_spec.rb +2 -2
  108. data/stories/all.rb +1 -1
  109. data/stories/example_groups/stories.rb +4 -3
  110. data/stories/mock_framework_integration/stories.rb +7 -0
  111. data/stories/mock_framework_integration/use_flexmock.story +9 -0
  112. data/stories/resources/spec/spec_with_flexmock.rb +18 -0
  113. metadata +21 -18
  114. data/pre_commit/lib/pre_commit.rb +0 -4
  115. data/pre_commit/lib/pre_commit/core.rb +0 -50
  116. data/pre_commit/lib/pre_commit/pre_commit.rb +0 -54
  117. data/pre_commit/lib/pre_commit/rspec.rb +0 -111
  118. data/pre_commit/lib/pre_commit/rspec_on_rails.rb +0 -313
  119. data/pre_commit/spec/pre_commit/pre_commit_spec.rb +0 -15
  120. data/pre_commit/spec/pre_commit/rspec_on_rails_spec.rb +0 -36
  121. data/pre_commit/spec/spec_helper.rb +0 -3
  122. data/pre_commit/spec/spec_suite.rb +0 -11
@@ -10,16 +10,17 @@ module Spec
10
10
  module Runner
11
11
  class << self
12
12
  def run_options # :nodoc:
13
- @run_options ||= ::Spec::Runner::OptionParser.parse(ARGV, $stderr, $stdout)
13
+ rspec_options
14
+ # @run_options ||= ::Spec::Runner::OptionParser.parse(ARGV, $stderr, $stdout)
14
15
  end
15
16
 
16
17
  def story_runner # :nodoc:
17
18
  unless @story_runner
18
- @story_runner = StoryRunner.new(scenario_runner, world_creator)
19
+ @story_runner = create_story_runner
19
20
  run_options.story_formatters.each do |formatter|
20
21
  register_listener(formatter)
21
22
  end
22
- Runner.register_exit_hook
23
+ self.register_exit_hook
23
24
  end
24
25
  @story_runner
25
26
  end
@@ -32,6 +33,10 @@ module Spec
32
33
  @world_creator ||= World
33
34
  end
34
35
 
36
+ def create_story_runner
37
+ StoryRunner.new(scenario_runner, world_creator)
38
+ end
39
+
35
40
  # Use this to register a customer output formatter.
36
41
  def register_listener(listener)
37
42
  story_runner.add_listener(listener) # run_started, story_started, story_ended, #run_ended
@@ -41,9 +46,8 @@ module Spec
41
46
 
42
47
  def register_exit_hook # :nodoc:
43
48
  at_exit do
44
- Runner.story_runner.run_stories unless $!
49
+ exit Runner.story_runner.run_stories unless $!
45
50
  end
46
- # TODO exit with non-zero status if run fails
47
51
  end
48
52
 
49
53
  def dry_run
@@ -26,9 +26,9 @@ module Spec
26
26
  @story_file = path
27
27
  end
28
28
 
29
- def run
29
+ def run(story_runner=Spec::Story::Runner.story_runner)
30
30
  raise "You must set a path to the file with the story. See the RDoc." if @story_file.nil?
31
- mediator = Spec::Story::Runner::StoryMediator.new(steps, Spec::Story::Runner.story_runner, @options)
31
+ mediator = Spec::Story::Runner::StoryMediator.new(steps, story_runner, @options)
32
32
  parser = Spec::Story::Runner::StoryParser.new(mediator)
33
33
 
34
34
  story_text = File.read(@story_file)
@@ -11,6 +11,12 @@ module Spec
11
11
  run_story_ignoring_scenarios(scenario.story, world)
12
12
 
13
13
  world.start_collecting_errors
14
+
15
+ unless scenario.body
16
+ @listeners.each { |l| l.scenario_pending(scenario.story.title, scenario.name, '') }
17
+ return true
18
+ end
19
+
14
20
  world.instance_eval(&scenario.body)
15
21
  if world.errors.empty?
16
22
  @listeners.each { |l| l.scenario_succeeded(scenario.story.title, scenario.name) }
@@ -19,8 +25,10 @@ module Spec
19
25
  @listeners.each { |l| l.scenario_pending(scenario.story.title, scenario.name, e.message) }
20
26
  else
21
27
  @listeners.each { |l| l.scenario_failed(scenario.story.title, scenario.name, e) }
28
+ return false
22
29
  end
23
30
  end
31
+ true
24
32
  end
25
33
 
26
34
  def add_listener(listener)
@@ -64,7 +64,7 @@
64
64
  title = @title
65
65
  narrative = @narrative
66
66
  scenarios = @scenarios.collect { |scenario| scenario.to_proc }
67
- options = @options.merge(:steps => @step_group)
67
+ options = @options.merge(:steps_for => @step_group)
68
68
  lambda do
69
69
  Story title, narrative, options do
70
70
  scenarios.each { |scenario| instance_eval(&scenario) }
@@ -36,6 +36,7 @@ module Spec
36
36
  def run_stories
37
37
  return if @stories.empty?
38
38
  @listeners.each { |l| l.run_started(scenarios.size) }
39
+ success = true
39
40
  @stories.each do |story|
40
41
  story.assign_steps_to(World)
41
42
  @current_story = story
@@ -45,7 +46,7 @@ module Spec
45
46
  type = story[:type] || Object
46
47
  args = story[:args] || []
47
48
  world = @world_creator.create(type, *args)
48
- @scenario_runner.run(scenario, world)
49
+ success = success & @scenario_runner.run(scenario, world)
49
50
  end
50
51
  @listeners.each { |l| l.story_ended(story.title, story.narrative) }
51
52
  World.step_mother.clear
@@ -53,6 +54,7 @@ module Spec
53
54
  unique_steps = (World.step_names.collect {|n| Regexp === n ? n.source : n.to_s}).uniq.sort
54
55
  @listeners.each { |l| l.collected_steps(unique_steps) }
55
56
  @listeners.each { |l| l.run_ended }
57
+ return success
56
58
  end
57
59
 
58
60
  def add_listener(listener)
@@ -1,8 +1,8 @@
1
1
  module Spec
2
2
  module Story
3
3
  class Step
4
- PARAM_PATTERN = /(\$\w*)/
5
- PARAM_OR_GROUP_PATTERN = /(\$\w*)|\(.*?\)/
4
+ PARAM_PATTERN = /([^\\]|^)(\$(?!\$)\w*)/
5
+ PARAM_OR_GROUP_PATTERN = /(\$(?!\$)\w*)|\(.*?\)/
6
6
 
7
7
  attr_reader :name
8
8
  def initialize(name, &block)
@@ -48,11 +48,11 @@ module Spec
48
48
  expression = string_or_regexp.source
49
49
  end
50
50
  while expression =~ PARAM_PATTERN
51
- expression.gsub!($1, "(.*?)")
51
+ expression.gsub!($2, "(.*?)")
52
52
  end
53
53
  @expression = Regexp.new("^#{expression}$")
54
54
  end
55
55
 
56
56
  end
57
57
  end
58
- end
58
+ end
@@ -19,17 +19,14 @@ module Spec
19
19
  end
20
20
 
21
21
  def assign_steps_to(assignee)
22
- if @params[:steps]
23
- assignee.use(@params[:steps])
24
- else
25
- case keys = @params[:steps_for]
26
- when Symbol
27
- keys = [keys]
28
- when nil
29
- keys = []
30
- end
31
- keys.each do |key|
32
- assignee.use(steps_for(key))
22
+ if steps=@params[:steps_for]
23
+ steps = [steps] unless steps.is_a?(Array)
24
+ steps.each do |step|
25
+ if step.is_a?(StepGroup)
26
+ assignee.use(step)
27
+ else
28
+ assignee.use(steps_for(step))
29
+ end
33
30
  end
34
31
  end
35
32
  end
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'spec/expectations'
3
2
  require 'spec/matchers'
4
3
  require 'spec/example/pending'
data/lib/spec/version.rb CHANGED
@@ -3,10 +3,10 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 1
5
5
  MINOR = 1
6
- TINY = 3
6
+ TINY = 4
7
7
  RELEASE_CANDIDATE = nil
8
8
 
9
- BUILD_TIME_UTC = 20080131122909
9
+ BUILD_TIME_UTC = 20080526202855
10
10
 
11
11
  STRING = [MAJOR, MINOR, TINY].join('.')
12
12
  TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
@@ -1,4 +1,6 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib", "spec", "mocks"))
2
+ require 'spec/mocks/framework'
3
+ require 'spec/mocks/extensions'
2
4
 
3
5
  module Spec
4
6
  module Plugins
@@ -49,7 +49,7 @@ HERE
49
49
  describe Rspec, "selection of rspec command" do
50
50
  include AutotestHelper
51
51
 
52
- before :each do
52
+ before(:each) do
53
53
  common_setup
54
54
  @rspec_autotest = Rspec.new
55
55
  end
@@ -83,7 +83,7 @@ HERE
83
83
  describe Rspec, "selection of rspec command (windows compatibility issues)" do
84
84
  include AutotestHelper
85
85
 
86
- before :each do
86
+ before(:each) do
87
87
  common_setup
88
88
  end
89
89
 
@@ -104,7 +104,7 @@ HERE
104
104
  end
105
105
 
106
106
  describe Rspec, "adding spec.opts --options" do
107
- before :each do
107
+ before(:each) do
108
108
  @rspec_autotest = Rspec.new
109
109
  end
110
110
 
@@ -120,7 +120,7 @@ HERE
120
120
  end
121
121
 
122
122
  describe Rspec do
123
- before :each do
123
+ before(:each) do
124
124
  @rspec_autotest = Rspec.new
125
125
  @rspec_autotest.stub!(:ruby).and_return "ruby"
126
126
  @rspec_autotest.stub!(:add_options_if_present).and_return "-O spec/spec.opts"
@@ -167,11 +167,11 @@ HERE
167
167
  describe Rspec, "consolidating failures" do
168
168
  include AutotestHelper
169
169
 
170
- before :each do
170
+ before(:each) do
171
171
  common_setup
172
172
  @rspec_autotest = Rspec.new
173
173
 
174
- @spec_file = "./spec/autotest/rspec_spec.rb"
174
+ @spec_file = "spec/autotest/rspec_spec.rb"
175
175
  @rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now})
176
176
  @rspec_autotest.stub!(:find_files_to_test).and_return true
177
177
  end
@@ -181,14 +181,16 @@ HERE
181
181
  end
182
182
 
183
183
  it "should return a hash with the spec filename => spec name for each failure or error" do
184
- @rspec_autotest.stub!(:test_files_for).and_return "./spec/autotest/rspec_spec.rb"
185
- foo = [
184
+ @rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/rspec_spec.rb"
185
+ failures = [
186
186
  [
187
187
  "false should be false",
188
- "expected: true,\n got: false (using ==)\n./spec/autotest/rspec_spec.rb:203:"
188
+ "expected: true,\n got: false (using ==)\n#{@spec_file}:203:"
189
189
  ]
190
190
  ]
191
- @rspec_autotest.consolidate_failures(foo).should == {@spec_file => ["false should be false"]}
191
+ @rspec_autotest.consolidate_failures(failures).should == {
192
+ @spec_file => ["false should be false"]
193
+ }
192
194
  end
193
195
 
194
196
  end
File without changes
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + "/../../../spec_helper"
2
+
3
+ module Spec
4
+ module Example
5
+ module AModule; end
6
+ class AClass; end
7
+
8
+ describe "With", AModule do
9
+ it "should have the described_type as 'AModule'" do
10
+ self.class.described_module.should == AModule
11
+ end
12
+ end
13
+
14
+ describe "With", AClass do
15
+ it "should have the described_module as nil" do
16
+ self.class.described_module.should be_nil
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + "/../../../spec_helper"
2
+
3
+ module Spec
4
+ module Example
5
+ module AModuleAutomaticallyIncluded
6
+ def call_method
7
+ @method_called = true
8
+ return "a string"
9
+ end
10
+
11
+ def method_called?
12
+ @method_called ? true : false
13
+ end
14
+ end
15
+
16
+ describe "Including modules in an example group" do
17
+ describe AModuleAutomaticallyIncluded do
18
+ before :each do
19
+ Kernel.stub!(:warn)
20
+ end
21
+
22
+ it "should return the correct values" do
23
+ self.method_called?.should be_false
24
+ self.call_method.should eql("a string")
25
+ self.method_called?.should be_true
26
+ end
27
+
28
+ it "should respond_to? the methods from the module" do
29
+ self.should respond_to(:method_called?)
30
+ self.should respond_to(:call_method)
31
+ end
32
+
33
+ it "should not respond_to? methods which do not come from the module (or are in Spec::ExampleGroup)" do
34
+ self.should_not respond_to(:adsfadfadadf_a_method_which_does_not_exist)
35
+ end
36
+
37
+ it "should respond_to? a method in Spec::ExampleGroup" do
38
+ self.should respond_to(:describe)
39
+ end
40
+
41
+ it "should issue a warning with Kernel.warn" do
42
+ Kernel.should_receive(:warn)
43
+ self.call_method
44
+ end
45
+
46
+ it "should issue a warning when the example calls the method which is automatically included" do
47
+ Kernel.should_receive(:warn).with("Modules will no longer be automatically included in RSpec version 1.1.4. Called from #{__FILE__}:#{__LINE__+1}")
48
+ self.method_called?
49
+ end
50
+
51
+ it "should issue a warning with the correct file and line numbers" do
52
+ Kernel.should_receive(:warn).with("Modules will no longer be automatically included in RSpec version 1.1.4. Called from #{__FILE__}:#{__LINE__+1}")
53
+ self.method_called?
54
+ end
55
+ end
56
+
57
+ describe AModuleAutomaticallyIncluded, "which is also manually included" do
58
+ include AModuleAutomaticallyIncluded
59
+
60
+ before :each do
61
+ Kernel.stub!(:warn)
62
+ end
63
+
64
+ it "should respond to the methods since it is included" do
65
+ self.should respond_to(:method_called?)
66
+ self.should respond_to(:call_method)
67
+ end
68
+
69
+ it "should not issue a warning, since the module is manually included" do
70
+ Kernel.should_not_receive(:warn)
71
+ self.method_called?
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,128 +1,143 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  module Spec
4
4
  module Example
5
- describe ExampleGroupFactory, "with :foobar registered as custom type" do
5
+ describe ExampleGroupFactory do
6
+ describe "#get" do
7
+ attr_reader :example_group
8
+ before do
9
+ @example_group = Class.new(ExampleGroup)
10
+ ExampleGroupFactory.register(:registered_type, @example_group)
11
+ end
6
12
 
7
- before do
8
- @example_group = Class.new(ExampleGroup)
9
- ExampleGroupFactory.register(:foobar, @example_group)
10
- end
13
+ after do
14
+ ExampleGroupFactory.reset
15
+ end
11
16
 
12
- after do
13
- ExampleGroupFactory.reset
14
- end
17
+ it "should #get the default ExampleGroup type when passed nil" do
18
+ ExampleGroupFactory.get(nil).should == ExampleGroup
19
+ end
15
20
 
16
- it "should #get the default ExampleGroup type when passed nil" do
17
- ExampleGroupFactory.get(nil).should == ExampleGroup
18
- end
21
+ it "should #get the default ExampleGroup for unregistered non-nil values" do
22
+ ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
23
+ end
19
24
 
20
- it "should #get the default ExampleGroup for unregistered non-nil values" do
21
- ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
22
- end
25
+ it "should #get custom type for :registered_type" do
26
+ ExampleGroupFactory.get(:registered_type).should == @example_group
27
+ end
23
28
 
24
- it "should #get custom type for :foobar" do
25
- ExampleGroupFactory.get(:foobar).should == @example_group
26
- end
29
+ it "should #get the actual type when that is passed in" do
30
+ ExampleGroupFactory.get(@example_group).should == @example_group
31
+ end
27
32
 
28
- it "should #get the actual type when that is passed in" do
29
- ExampleGroupFactory.get(@example_group).should == @example_group
33
+ it "should get the custom type after setting the default" do
34
+ @example_group2 = Class.new(ExampleGroup)
35
+ ExampleGroupFactory.default(@example_group2)
36
+ ExampleGroupFactory.get(:registered_type).should == @example_group
37
+ end
30
38
  end
31
39
 
32
- end
40
+ describe "#create_example_group" do
41
+ attr_reader :parent_example_group
42
+ before do
43
+ @parent_example_group = Class.new(ExampleGroup) do
44
+ def initialize(*args, &block)
45
+ ;
46
+ end
47
+ end
48
+ end
33
49
 
34
- describe ExampleGroupFactory, "#create_example_group" do
35
- it "should create a uniquely named class" do
36
- example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {}
37
- example_group.name.should =~ /Spec::Example::ExampleGroup::Subclass_\d+/
38
- end
50
+ it "should create a uniquely named class" do
51
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {}
52
+ example_group.name.should =~ /Spec::Example::ExampleGroup::Subclass_\d+/
53
+ end
39
54
 
40
- it "should create a Spec::Example::Example subclass by default" do
41
- example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {}
42
- example_group.superclass.should == Spec::Example::ExampleGroup
43
- end
55
+ it "should create a Spec::Example::Example subclass by default" do
56
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {}
57
+ example_group.superclass.should == Spec::Example::ExampleGroup
58
+ end
44
59
 
45
- it "should create a Spec::Example::Example when :type => :default" do
46
- example_group = Spec::Example::ExampleGroupFactory.create_example_group(
47
- "example_group", :type => :default
48
- ) {}
49
- example_group.superclass.should == Spec::Example::ExampleGroup
50
- end
60
+ describe "when :type => :default" do
61
+ it "should create a Spec::Example::Example" do
62
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group(
63
+ "example_group", :type => :default
64
+ ) {}
65
+ example_group.superclass.should == Spec::Example::ExampleGroup
66
+ end
67
+
68
+ it "should create a Spec::Example::Example" do
69
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group(
70
+ "example_group", :type => :default
71
+ ) {}
72
+ example_group.superclass.should == Spec::Example::ExampleGroup
73
+ end
74
+ end
51
75
 
52
- it "should create a Spec::Example::Example when :type => :default" do
53
- example_group = Spec::Example::ExampleGroupFactory.create_example_group(
54
- "example_group", :type => :default
55
- ) {}
56
- example_group.superclass.should == Spec::Example::ExampleGroup
57
- end
76
+ describe "when :type => :something_other_than_default" do
77
+ it "should create specified type" do
78
+ Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
79
+ non_default_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
80
+ "example_group", :type => :something_other_than_default
81
+ ) {}
82
+ non_default_example_group.superclass.should == parent_example_group
83
+ end
84
+ end
58
85
 
59
- it "should create specified type when :type => :something_other_than_default" do
60
- klass = Class.new(ExampleGroup) do
61
- def initialize(*args, &block); end
86
+ it "should create a type indicated by :spec_path" do
87
+ Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
88
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
89
+ "example_group", :spec_path => "./spec/something_other_than_default/some_spec.rb"
90
+ ) {}
91
+ custom_example_group.superclass.should == parent_example_group
62
92
  end
63
- Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass)
64
- example_group = Spec::Example::ExampleGroupFactory.create_example_group(
65
- "example_group", :type => :something_other_than_default
66
- ) {}
67
- example_group.superclass.should == klass
68
- end
69
-
70
- it "should create a type indicated by :spec_path" do
71
- klass = Class.new(ExampleGroup) do
72
- def initialize(*args, &block); end
73
- end
74
- Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass)
75
- example_group = Spec::Example::ExampleGroupFactory.create_example_group(
76
- "example_group", :spec_path => "./spec/something_other_than_default/some_spec.rb"
77
- ) {}
78
- example_group.superclass.should == klass
79
- end
80
-
81
- it "should create a type indicated by :spec_path (with spec_path generated by caller on windows)" do
82
- klass = Class.new(ExampleGroup) do
83
- def initialize(*args, &block); end
84
- end
85
- Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass)
86
- example_group = Spec::Example::ExampleGroupFactory.create_example_group(
87
- "example_group", :spec_path => "./spec\\something_other_than_default\\some_spec.rb"
88
- ) {}
89
- example_group.superclass.should == klass
90
- end
91
-
92
- it "should create and register a Spec::Example::Example if :shared => true" do
93
- shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
94
- "name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller, :shared => true
95
- ) {}
96
- shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
97
- SharedExampleGroup.shared_example_groups.should include(shared_example_group)
98
- end
99
93
 
100
- it "should favor the :type over the :spec_path" do
101
- klass = Class.new(ExampleGroup) do
102
- def initialize(*args, &block); end
94
+ it "should create a type indicated by :spec_path (with spec_path generated by caller on windows)" do
95
+ Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
96
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
97
+ "example_group",
98
+ :spec_path => "./spec\\something_other_than_default\\some_spec.rb"
99
+ ) {}
100
+ custom_example_group.superclass.should == parent_example_group
103
101
  end
104
- Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass)
105
- example_group = Spec::Example::ExampleGroupFactory.create_example_group(
106
- "name", :spec_path => '/blah/spec/models/blah.rb', :type => :something_other_than_default
107
- ) {}
108
- example_group.superclass.should == klass
109
- end
110
102
 
111
- it "should register ExampleGroup by default" do
112
- example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
103
+ describe "when :shared => true" do
104
+ attr_reader :shared_example_group
105
+ before do
106
+ @shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
107
+ "name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller, :shared => true
108
+ ) {}
109
+ end
110
+
111
+ it "should create and register a Spec::Example::Example" do
112
+ shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
113
+ SharedExampleGroup.shared_example_groups.should include(shared_example_group)
114
+ end
113
115
  end
114
- rspec_options.example_groups.should include(example_group)
115
- end
116
116
 
117
- it "should enable unregistering of ExampleGroups" do
118
- example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
119
- unregister
117
+ it "should favor the :type over the :spec_path" do
118
+ Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
119
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
120
+ "name", :spec_path => '/blah/spec/models/blah.rb', :type => :something_other_than_default
121
+ ) {}
122
+ custom_example_group.superclass.should == parent_example_group
123
+ end
124
+
125
+ it "should register ExampleGroup by default" do
126
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
127
+ end
128
+ rspec_options.example_groups.should include(example_group)
129
+ end
130
+
131
+ it "should enable unregistering of ExampleGroups" do
132
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
133
+ unregister
134
+ end
135
+ rspec_options.example_groups.should_not include(example_group)
136
+ end
137
+
138
+ after(:each) do
139
+ Spec::Example::ExampleGroupFactory.reset
120
140
  end
121
- rspec_options.example_groups.should_not include(example_group)
122
- end
123
-
124
- after(:each) do
125
- Spec::Example::ExampleGroupFactory.reset
126
141
  end
127
142
  end
128
143
  end