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 +0 -1
- data/lib/rspec-steps/duckpunch/example-group.rb +15 -7
- data/lib/rspec-steps/duckpunch/object-extensions.rb +6 -11
- data/lib/rspec-steps/stepwise.rb +111 -87
- data/spec/example_group.rb +5 -5
- data/spec_help/rspec-sandbox.rb +30 -28
- metadata +8 -8
data/lib/rspec-steps.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
+
require 'rspec/core/example_group'
|
1
2
|
require 'rspec-steps/stepwise'
|
2
3
|
|
3
|
-
module RSpec::
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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::
|
4
|
-
|
5
|
-
|
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
|
data/lib/rspec-steps/stepwise.rb
CHANGED
@@ -1,112 +1,136 @@
|
|
1
1
|
module RSpecStepwise
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
46
|
+
def eval_around_eachs(example)
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
def eval_before_eachs(example)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
def eval_after_eachs(example)
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
+
module_eval_with_args(*args, &shared_block)
|
86
|
+
module_eval(&customization_block) if customization_block
|
87
|
+
end
|
85
88
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
data/spec/example_group.rb
CHANGED
@@ -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 {
|
data/spec_help/rspec-sandbox.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
40
|
-
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
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:
|
122
|
+
hash: 15
|
123
123
|
segments:
|
124
124
|
- 2
|
125
|
-
-
|
126
|
-
version: "2.
|
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.
|
394
|
+
- rspec-steps-0.0.4 RDoc
|
395
395
|
require_paths:
|
396
396
|
- lib/
|
397
397
|
required_ruby_version: !ruby/object:Gem::Requirement
|