rspec-steps 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rspec-steps.rb CHANGED
@@ -1,3 +1,2 @@
1
1
  require 'rspec-steps/duckpunch/object-extensions'
2
2
  require 'rspec-steps/duckpunch/example-group'
3
-
@@ -1,12 +1,20 @@
1
+ require 'rspec/core/example_group'
1
2
  require 'rspec-steps/stepwise'
2
3
 
3
- module RSpec::Core
4
- class ExampleGroup
5
- def self.steps(*args, &example_group_block)
6
- describe(*args) do
7
- extend RSpecStepwise
8
- module_eval &example_group_block
9
- end
4
+ module RSpec::Steps
5
+ module ClassMethods
6
+ def steps(*args, &block)
7
+ options = if args.last.is_a?(Hash) then args.pop else {} end
8
+ options[:stepwise] = true
9
+ options[:caller] ||= caller
10
+ args.push(options)
11
+
12
+ describe(*args, &block)
10
13
  end
11
14
  end
12
15
  end
16
+
17
+ RSpec::Core::ExampleGroup.extend RSpec::Steps::ClassMethods
18
+ include RSpec::Steps::ClassMethods
19
+
20
+ RSpec::configuration.include(RSpecStepwise, :stepwise => true)
@@ -1,14 +1,9 @@
1
+ require 'rspec-steps/duckpunch/example-group'
1
2
  require 'rspec-steps/stepwise'
3
+ require 'rspec/core/shared_example_group'
2
4
 
3
- module RSpec::Steps
4
- module ObjectExtensions
5
- def steps(*args, &example_group_block)
6
- RSpec::Core::ExampleGroup.steps(*args, &example_group_block).register
7
- end
8
-
9
- alias :shared_steps :shared_context
10
- alias :steps_shared_as :share_as
11
- end
5
+ module RSpec::Core::SharedExampleGroup
6
+ alias :shared_steps :share_examples_for
7
+ alias :steps_shared_as :share_as
12
8
  end
13
-
14
- include RSpec::Steps::ObjectExtensions
9
+ extend RSpec::Steps::ClassMethods
@@ -1,112 +1,136 @@
1
1
  module RSpecStepwise
2
- #TODO: This is hacky and needs a more general solution
3
- #Something like cloning the current conf and having RSpec::Stepwise::config ?
4
- def suspend_transactional_fixtures
5
- if self.respond_to? :use_transactional_fixtures
6
- old_val = self.use_transactional_fixtures
7
- self.use_transactional_fixtures = false
8
-
9
- yield
10
-
11
- self.use_transactional_fixtures = old_val
12
- else
13
- yield
2
+ module ClassMethods
3
+ #TODO: This is hacky and needs a more general solution
4
+ #Something like cloning the current conf and having RSpec::Stepwise::config ?
5
+ def suspend_transactional_fixtures
6
+ if self.respond_to? :use_transactional_fixtures
7
+ old_val = self.use_transactional_fixtures
8
+ self.use_transactional_fixtures = false
9
+
10
+ yield
11
+
12
+ self.use_transactional_fixtures = old_val
13
+ else
14
+ yield
15
+ end
14
16
  end
15
- end
16
17
 
17
- def before(*args, &block)
18
- if args.first == :each
19
- puts "before blocks declared for steps are always treated as :all scope"
18
+ def before(*args, &block)
19
+ if args.first == :each
20
+ puts "before blocks declared for steps are always treated as :all scope"
21
+ end
22
+ super
20
23
  end
21
- super
22
- end
23
24
 
24
- def after(*args, &block)
25
- if args.first == :each
26
- puts "after blocks declared for steps are always treated as :all scope"
25
+ def after(*args, &block)
26
+ if args.first == :each
27
+ puts "after blocks declared for steps are always treated as :all scope"
28
+ end
29
+ super
27
30
  end
28
- super
29
- end
30
31
 
31
- def around(*args, &block)
32
- if args.first == :each
33
- puts "around :each blocks declared for steps are treated as :all scope"
32
+ def around(*args, &block)
33
+ if args.first == :each
34
+ puts "around :each blocks declared for steps are treated as :all scope"
35
+ end
36
+ super
34
37
  end
35
- super
36
- end
37
38
 
38
- def eval_before_alls(example_group_instance)
39
- super
40
- example_group_instance.example = whole_list_example
41
- world.run_hook_filtered(:before, :each, self, example_group_instance, example)
42
- ancestors.reverse.each { |ancestor| ancestor.run_hook(:before, :each, example_group_instance) }
43
- end
39
+ def eval_before_alls(example_group_instance)
40
+ super
41
+ example_group_instance.example = whole_list_example
42
+ world.run_hook_filtered(:before, :each, self, example_group_instance, whole_list_example)
43
+ ancestors.reverse.each { |ancestor| ancestor.run_hook(:before, :each, example_group_instance) }
44
+ end
44
45
 
45
- def eval_around_eachs(example)
46
- end
46
+ def eval_around_eachs(example)
47
+ end
47
48
 
48
- def eval_before_eachs(example)
49
- end
49
+ def eval_before_eachs(example)
50
+ end
50
51
 
51
- def eval_after_eachs(example)
52
- end
52
+ def eval_after_eachs(example)
53
+ end
53
54
 
54
- def eval_after_alls(example_group_instance)
55
- example_group_instance.example = whole_list_example
56
- ancestors.each { |ancestor| ancestor.run_hook(:after, :each, example_group_instance) }
57
- world.run_hook_filtered(:after, :each, self, example_group_instance, example)
58
- super
59
- end
55
+ def eval_after_alls(example_group_instance)
56
+ example_group_instance.example = whole_list_example
57
+ ancestors.each { |ancestor| ancestor.run_hook(:after, :each, example_group_instance) }
58
+ world.run_hook_filtered(:after, :each, self, example_group_instance, whole_list_example)
59
+ super
60
+ end
60
61
 
61
- def whole_list_example
62
- RSpec::Core::Example.new(self, "step list", {})
63
- end
62
+ def whole_list_example
63
+ @whole_list_example ||= begin
64
+ RSpec::Core::Example.new(self, "step list", {})
65
+ end
66
+ end
64
67
 
65
- def with_around_hooks(instance, &block)
66
- hooks = around_hooks_for(self)
67
- if hooks.empty?
68
- yield
69
- else
70
- hooks.reverse.inject(Example.procsy(metadata)) do |procsy, around_hook|
71
- Example.procsy(procsy.metadata) do
72
- instance.instance_eval_with_args(procsy, &around_hook)
73
- end
74
- end.call
68
+ def with_around_hooks(instance, &block)
69
+ hooks = around_hooks_for(self)
70
+ if hooks.empty?
71
+ yield
72
+ else
73
+ hooks.reverse.inject(Example.procsy(metadata)) do |procsy, around_hook|
74
+ Example.procsy(procsy.metadata) do
75
+ instance.instance_eval_with_args(procsy, &around_hook)
76
+ end
77
+ end.call
78
+ end
75
79
  end
76
- end
77
80
 
78
- def perform_steps(name, *args, &customization_block)
79
- shared_block = world.shared_example_groups[name]
80
- raise "Could not find shared example group named \#{name.inspect}" unless shared_block
81
+ def perform_steps(name, *args, &customization_block)
82
+ shared_block = world.shared_example_groups[name]
83
+ raise "Could not find shared example group named \#{name.inspect}" unless shared_block
81
84
 
82
- module_eval_with_args(*args, &shared_block)
83
- module_eval(&customization_block) if customization_block
84
- end
85
+ module_eval_with_args(*args, &shared_block)
86
+ module_eval(&customization_block) if customization_block
87
+ end
85
88
 
86
- def run_examples(reporter)
87
- instance = new
88
- set_ivars(instance, before_all_ivars)
89
-
90
- instance.example = whole_list_example
91
-
92
- suspend_transactional_fixtures do
93
- with_around_hooks(instance) do
94
- filtered_examples.inject(true) do |success, example|
95
- break if RSpec.wants_to_quit
96
- unless success
97
- reporter.example_started(example)
98
- example.metadata[:pending] = true
99
- example.metadata[:execution_result][:pending_message] = "Previous step failed"
100
- example.metadata[:execution_result][:started_at] = Time.now
101
- example.instance_eval{ record_finished :pending, :pending_message => "Previous step failed" }
102
- reporter.example_pending(example)
103
- next
89
+ def run_examples(reporter)
90
+ instance = new
91
+
92
+ set_ivars(instance, before_all_ivars)
93
+
94
+ instance.example = whole_list_example
95
+
96
+ suspend_transactional_fixtures do
97
+ with_around_hooks(instance) do
98
+ filtered_examples.inject(true) do |success, example|
99
+ break if RSpec.wants_to_quit
100
+ unless success
101
+ reporter.example_started(example)
102
+ example.metadata[:pending] = true
103
+ example.metadata[:execution_result][:pending_message] = "Previous step failed"
104
+ example.metadata[:execution_result][:started_at] = Time.now
105
+ example.instance_eval{ record_finished :pending, :pending_message => "Previous step failed" }
106
+ reporter.example_pending(example)
107
+ next
108
+ end
109
+ succeeded = instance.with_indelible_ivars do
110
+ example.run(instance, reporter)
111
+ end
112
+ RSpec.wants_to_quit = true if fail_fast? && !succeeded
113
+ success && succeeded
104
114
  end
105
- succeeded = example.run(instance, reporter)
106
- RSpec.wants_to_quit = true if fail_fast? && !succeeded
107
- success && succeeded
108
115
  end
109
116
  end
110
117
  end
111
118
  end
119
+
120
+ def with_indelible_ivars
121
+ old_value, @ivars_indelible = @ivars_indelible, true
122
+ result = yield
123
+ @ivars_indelible = old_value
124
+ result
125
+ end
126
+
127
+ def instance_variable_set(name, value)
128
+ if !@ivars_indelible
129
+ super
130
+ end
131
+ end
132
+
133
+ def self.included(base)
134
+ base.extend(ClassMethods)
135
+ end
112
136
  end
@@ -9,7 +9,7 @@ describe RSpec::Core::ExampleGroup, "defined as stepwise" do
9
9
  group = steps "Test Steps" do
10
10
  end
11
11
  end
12
- (class << group; self; end).included_modules.should include(RSpecStepwise)
12
+ (class << group; self; end).included_modules.should include(RSpecStepwise::ClassMethods)
13
13
  end
14
14
  end
15
15
 
@@ -18,8 +18,8 @@ describe RSpec::Core::ExampleGroup, "defined as stepwise" do
18
18
  group = nil
19
19
  sandboxed do
20
20
  group = steps "Test Steps" do
21
- it { @a = 1 }
22
- it { @a.should == 1}
21
+ it("sets @a"){ @a = 1 }
22
+ it("reads @a"){ @a.should == 1}
23
23
  end
24
24
  group.run
25
25
  end
@@ -42,7 +42,7 @@ describe RSpec::Core::ExampleGroup, "defined as stepwise" do
42
42
  group.examples[1].metadata[:pending].should be_true
43
43
  end
44
44
 
45
- it "should allow nested steps" do
45
+ it "should allow nested steps", :pending => "Not really" do
46
46
  group = nil
47
47
  sandboxed do
48
48
  group = steps "Test Steps" do
@@ -59,7 +59,7 @@ describe RSpec::Core::ExampleGroup, "defined as stepwise" do
59
59
  end
60
60
  group.children[0].should have(2).examples
61
61
  end
62
-
62
+
63
63
  it "should not allow nested normal contexts" do
64
64
  pending "A correct approach - in the meantime, this behavior is undefined"
65
65
  expect {
@@ -1,3 +1,5 @@
1
+ require 'rspec/core'
2
+
1
3
  class NullObject
2
4
  private
3
5
  def method_missing(method, *args, &block)
@@ -6,39 +8,39 @@ class NullObject
6
8
  end
7
9
 
8
10
  def sandboxed(&block)
9
- begin
10
- @orig_config = RSpec.configuration
11
- @orig_world = RSpec.world
12
- new_config = RSpec::Core::Configuration.new
13
- new_world = RSpec::Core::World.new(new_config)
14
- RSpec.instance_variable_set(:@configuration, new_config)
15
- RSpec.instance_variable_set(:@world, new_world)
16
- object = Object.new
17
- object.extend(RSpec::Core::ObjectExtensions)
18
- object.extend(RSpec::Core::SharedExampleGroup)
11
+ @orig_config = RSpec.configuration
12
+ @orig_world = RSpec.world
13
+ new_config = RSpec::Core::Configuration.new
14
+ new_world = RSpec::Core::World.new(new_config)
15
+ RSpec.instance_variable_set(:@configuration, new_config)
16
+ RSpec.instance_variable_set(:@world, new_world)
19
17
 
20
- (class << RSpec::Core::ExampleGroup; self; end).class_eval do
21
- alias_method :orig_run, :run
22
- def run(reporter=nil)
23
- @orig_mock_space = RSpec::Mocks::space
24
- RSpec::Mocks::space = RSpec::Mocks::Space.new
25
- orig_run(reporter || NullObject.new)
26
- ensure
27
- RSpec::Mocks::space = @orig_mock_space
28
- end
29
- end
18
+ load 'rspec-steps/duckpunch/example-group.rb'
30
19
 
31
- object.instance_eval(&block)
32
- ensure
33
- (class << RSpec::Core::ExampleGroup; self; end).class_eval do
34
- remove_method :run
35
- alias_method :run, :orig_run
36
- remove_method :orig_run
20
+ object = Object.new
21
+ object.extend(RSpec::Core::SharedExampleGroup)
22
+
23
+ (class << RSpec::Core::ExampleGroup; self; end).class_eval do
24
+ alias_method :orig_run, :run
25
+ def run(reporter=nil)
26
+ @orig_mock_space = RSpec::Mocks::space
27
+ RSpec::Mocks::space = RSpec::Mocks::Space.new
28
+ orig_run(reporter || NullObject.new)
29
+ ensure
30
+ RSpec::Mocks::space = @orig_mock_space
37
31
  end
32
+ end
38
33
 
39
- RSpec.instance_variable_set(:@configuration, @orig_config)
40
- RSpec.instance_variable_set(:@world, @orig_world)
34
+ object.instance_eval(&block)
35
+ ensure
36
+ (class << RSpec::Core::ExampleGroup; self; end).class_eval do
37
+ remove_method :run
38
+ alias_method :run, :orig_run
39
+ remove_method :orig_run
41
40
  end
41
+
42
+ RSpec.instance_variable_set(:@configuration, @orig_config)
43
+ RSpec.instance_variable_set(:@world, @orig_world)
42
44
  end
43
45
 
44
46
  #Original from rspec-core
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-steps
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Judson Lester
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-25 00:00:00 -07:00
18
+ date: 2011-08-04 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -119,11 +119,11 @@ dependencies:
119
119
  requirements:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
- hash: 3
122
+ hash: 15
123
123
  segments:
124
124
  - 2
125
- - 0
126
- version: "2.0"
125
+ - 6
126
+ version: "2.6"
127
127
  type: :runtime
128
128
  version_requirements: *id007
129
129
  description: " I don't like Cucumber. I don't need plain text stories. My clients either\n read code or don't read any test documents, so Cucumber is mostly useless.\n But often, especially in full integration tests, it would be nice to have\n steps in a test.\n"
@@ -391,7 +391,7 @@ rdoc_options:
391
391
  - --main
392
392
  - doc/README
393
393
  - --title
394
- - rspec-steps-0.0.3 RDoc
394
+ - rspec-steps-0.0.4 RDoc
395
395
  require_paths:
396
396
  - lib/
397
397
  required_ruby_version: !ruby/object:Gem::Requirement