rspec-example_steps 0.2.4 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b8172abd39b0b7013b32df9b0975101cf9f40928b02b3be3a88e4abbcbe3b4f2
4
+ data.tar.gz: d69aa231297cefa1b45ee6fbbe7bbccc16572117f9bf066f20ad3eed50aaedd1
5
+ SHA512:
6
+ metadata.gz: 7dc7552ba3b6cc78140942dec817cb323a5721ebf920e344b9f61405bd4ea6e99e380ca4e68665a56a1a9672446150482790f60437d20efc5fe31b9a46c6829b
7
+ data.tar.gz: a06829b9fb3749a89c50abbd335f13ba3c7c1ff0d555a7bbc78aa980e43fc5cd81d50340fc1f3b0d4cde820636873a69d83b4384d5b65a8dcfbb9ab75335c542
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 3.1.0
4
+
5
+ * Removed shared_steps feature
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rspec', '2.7.0'
5
+ gem 'rspec', '3.0.0'
data/README.md CHANGED
@@ -2,133 +2,88 @@
2
2
 
3
3
  Given/When/Then/And/But steps for RSpec examples
4
4
 
5
- ### Example
6
-
7
- require 'rspec/example_steps'
5
+ ### Description
8
6
 
9
- context "Searching" do
10
- Steps "Result found" do
11
- Given "I am on search page" do
12
- page.visit("/search")
13
- page.should have_content("Search")
14
- end
7
+ This gem brings two major functionality to your `spec/features`
15
8
 
16
- When "I search something" do
17
- page.fill_in('Search', :with => 'John')
18
- page.click_button "Go"
19
- end
9
+ * Verbosity for rspec documentation formatter.
10
+ * Ability to comment or describe set of actions in example into some step.
20
11
 
21
- Then "I should see result" do
22
- page.should have_content("Result")
23
- end
24
- end
25
- end
26
-
27
- ### Documentation formatting output:
12
+ ### Installation
28
13
 
29
- Searching
30
- User succesfully replaces device
31
- Given I am on search page
32
- When I search something
33
- Then I should see result
14
+ * For rspec v2 use gem **v0.2.x** or rspec2 branch
15
+ * For rspec v3 use gem **v3.x.x** or master branch
34
16
 
17
+ ```ruby
18
+ gem 'rspec-example_steps'
19
+ ```
35
20
 
36
- ### Shared steps
21
+ Add to `spec/spec_helper.rb`
37
22
 
38
- Use _shared_steps_ do define block that will be evaluated in the context of example using _include_steps_.
23
+ ```ruby
24
+ require 'rspec/example_steps'
25
+ ```
39
26
 
40
- Shared _steps_ behavior is simular to shared _example_ but context is example nor example_group.
27
+ ### Example
41
28
 
42
- ### Example with shared steps
29
+ `spec/features/search_spec.rb`
43
30
 
44
- shared_steps "login" do
45
- When "I go to login page" do
46
- page.visit '/login'
47
- end
48
- When "I put credentials" do
49
- page.fill_in 'Login', :with => 'jack@example.com'
50
- page.fill_in 'Password', :with => 'password''
51
- end
52
- Then "I should be logged in" do
53
- page.status_code.should == 200
54
- page.should have_content("Welcome jack@example.com")
55
- end
31
+ ```ruby
32
+ context 'Searching' do
33
+ Steps 'Result found' do
34
+ Given 'I am on search page' do
35
+ visit '/search'
36
+ expect(page).to have_content('Search')
56
37
  end
57
38
 
58
- shared_steps "logout" do
59
- page.visit '/logout'
60
- page.status_code.should == 200
39
+ When 'I search something' do
40
+ fill_in 'Search', with: 'John'
41
+ click_button 'Go'
61
42
  end
62
43
 
63
- context "user flow"
64
- Steps "User updates profile description" do
65
- include_steps "login"
66
- When "I update profile description" do
67
- ...
68
- end
69
- include_steps "logout"
70
- end
71
-
72
- Steps "User updates profile avatar" do
73
- include_steps "login"
74
- When "I update profile avatar" do
75
- ...
76
- end
77
- include_steps "logout"
78
- end
44
+ Then 'I should see result' do
45
+ expect(page).to have_content('Result')
79
46
  end
47
+ end
48
+ end
49
+ ```
80
50
 
81
- ### Passing arguments to shared steps
82
-
83
- It's possible to customize shared steps. See example
84
-
85
- ### Example with shared steps with arguments
86
-
87
- shared_steps "login" do |email, password|
88
- When "I go to login page" do
89
- page.visit '/login'
90
- end
91
- When "I put credentials" do
92
- page.fill_in 'Login', :with => email
93
- page.fill_in 'Password', :with => password
94
- end
95
- end
51
+ ### Documentation formatting output:
96
52
 
97
- shared_steps "invalid login" do
98
- Then "I should see login error" do
99
- ...
100
- end
101
- end
102
-
103
- Steps "User provides wrong email" do
104
- include_steps "login", 'jack', 'qwerty'
105
- include_steps "invalid login"
106
- end
107
-
108
- Steps "User provides wrong password" do
109
- include_steps "login", 'jack@example.com', 'bla'
110
- include_steps "invalid login"
111
- end
53
+ `rspec -fd spec/features/search_spec.rb`
112
54
 
55
+ <pre>
56
+ Searching
57
+ User succesfully replaces device
58
+ Given I am on search page
59
+ When I search something
60
+ Then I should see result
61
+ </pre>
113
62
 
114
63
  ### Pending steps
115
64
 
116
65
  Simular to Example :pending behavior:
117
66
 
118
- Steps "User login" do
119
- # just skip block
120
- When "I go to login"
67
+ ```ruby
68
+ Steps 'User login' do
69
+ # just skip block
70
+ When 'I go to login'
121
71
 
122
- # pass :pending => true option
123
- Then "I should see welcome", :pending => true do
124
- ...
125
- end
72
+ # pass pending: true option
73
+ Then 'I should see welcome', pending: true do
74
+ ...
75
+ end
126
76
 
127
- # pass :pending => "some pending message"
128
- Then "I should see last login IP", :pending => "WIP" do
129
- ...
130
- end
131
- end
77
+ # pass pending: 'some pending message'
78
+ Then 'I should see last login IP', pending: 'WIP' do
79
+ ...
80
+ end
81
+ end
82
+ ```
83
+
84
+ ## Authors
85
+
86
+ * [Andriy Yanko](http://ayanko.github.io)
132
87
 
133
88
  ## License
134
89
 
@@ -1,27 +1,25 @@
1
1
  require 'rspec/core'
2
- require 'rspec/core/formatters/base_formatter'
2
+ require 'rspec/core/formatters'
3
+ require 'rspec/core/formatters/console_codes'
3
4
  require 'rspec/core/formatters/documentation_formatter'
4
5
  require 'rspec/core/example_group'
5
6
  require 'rspec/core/reporter'
6
7
  require 'rspec/core/world'
7
8
 
8
- require 'rspec/example_steps/base_formatter'
9
9
  require 'rspec/example_steps/documentation_formatter'
10
10
  require 'rspec/example_steps/example_group'
11
+ require 'rspec/example_steps/notification'
11
12
  require 'rspec/example_steps/reporter'
12
13
  require 'rspec/example_steps/world'
13
14
 
14
- RSpec::Core::Formatters::BaseFormatter.send :include, RSpec::ExampleSteps::BaseFormatter
15
15
  RSpec::Core::Formatters::DocumentationFormatter.send :include, RSpec::ExampleSteps::DocumentationFormatter
16
16
  RSpec::Core::ExampleGroup.send :include, RSpec::ExampleSteps::ExampleGroup
17
17
  RSpec::Core::Reporter.send :include, RSpec::ExampleSteps::Reporter
18
18
  RSpec::Core::World.send :include, RSpec::ExampleSteps::World
19
19
 
20
- if RSpec::Core::ExampleGroup.singleton_class.respond_to?(:define_example_method, true)
21
- RSpec::Core::ExampleGroup.singleton_class.define_example_method :Steps, :with_steps => true
22
- else
23
- RSpec::Core::ExampleGroup.define_example_method :Steps, :with_steps => true
24
- end
20
+ RSpec::Core::ExampleGroup.define_example_method :Steps, with_steps: true
25
21
 
26
- require 'rspec/example_steps/shared_steps'
27
- include RSpec::ExampleSteps::SharedSteps
22
+ if formatter = RSpec.world.reporter.find_registered_formatter(RSpec::Core::Formatters::DocumentationFormatter)
23
+ RSpec.world.reporter.register_listener formatter,
24
+ :example_started, :example_step_passed, :example_step_pending, :example_step_failed
25
+ end
@@ -14,55 +14,42 @@ module RSpec
14
14
  end
15
15
 
16
16
  module InstanceMethods
17
- def example_started_with_steps(example)
18
- example_started_without_steps(example)
17
+ def example_started(notification)
18
+ end
19
+
20
+ def example_started_with_steps(notification)
21
+ example_started_without_steps(notification)
19
22
 
20
- if example.options[:with_steps]
21
- full_message = "#{current_indentation}#{example.description}"
22
- if respond_to?(:default_color, true)
23
- output.puts default_color(full_message)
24
- else
25
- output.puts white(full_message)
26
- end
23
+ if notification.example.metadata[:with_steps]
24
+ full_message = "#{current_indentation}#{notification.example.description}"
25
+ output.puts Core::Formatters::ConsoleCodes.wrap(full_message, :default)
27
26
  end
28
27
  end
29
28
 
30
- def example_passed_with_steps(example)
31
- example_passed_without_steps(example) unless example.options[:with_steps]
29
+ def example_passed_with_steps(notification)
30
+ example_passed_without_steps(notification) unless notification.example.metadata[:with_steps]
32
31
  end
33
32
 
34
- def example_step_passed(example_group, type, message, options)
35
- full_message = "#{current_indentation} #{type.to_s.capitalize} #{message}"
36
- if respond_to?(:success_color, true)
37
- output.puts success_color(full_message)
38
- else
39
- output.puts green(full_message)
40
- end
33
+ def example_step_passed(notification)
34
+ full_message = "#{current_indentation} #{notification.type.to_s.capitalize} #{notification.message}"
35
+ output.puts Core::Formatters::ConsoleCodes.wrap(full_message, :success)
41
36
  end
42
37
 
43
- def example_step_pending(example_group, type, message, options)
44
- full_message = "#{current_indentation} #{type.to_s.capitalize} #{message}"
38
+ def example_step_pending(notification)
39
+ full_message = "#{current_indentation} #{notification.type.to_s.capitalize} #{notification.message}"
45
40
 
46
- if options[:pending] && options[:pending] != true
47
- full_message << " (PENDING: #{options[:pending]})"
41
+ if notification.options[:pending] && notification.options[:pending] != true
42
+ full_message << " (PENDING: #{notification.options[:pending]})"
48
43
  else
49
44
  full_message << " (PENDING)"
50
45
  end
51
46
 
52
- if respond_to?(:pending_color, true)
53
- output.puts pending_color(full_message)
54
- else
55
- output.puts yellow(full_message)
56
- end
47
+ output.puts Core::Formatters::ConsoleCodes.wrap(full_message, :pending)
57
48
  end
58
49
 
59
- def example_step_failed(example_group, type, message, options)
60
- full_message = "#{current_indentation} #{type.to_s.capitalize} #{message} (FAILED)"
61
- if respond_to?(:failure_color, true)
62
- output.puts failure_color(full_message)
63
- else
64
- output.puts red(full_message)
65
- end
50
+ def example_step_failed(notification)
51
+ full_message = "#{current_indentation} #{notification.type.to_s.capitalize} #{notification.message} (FAILED)"
52
+ output.puts Core::Formatters::ConsoleCodes.wrap(full_message, :failure)
66
53
  end
67
54
  end
68
55
  end
@@ -2,85 +2,30 @@ module RSpec
2
2
  module ExampleSteps
3
3
  module ExampleGroup
4
4
  def include_steps(*args)
5
- name = args.shift
5
+ name = args.shift
6
6
  shared_block = RSpec.world.shared_example_steps[name]
7
7
  shared_block or raise ArgumentError, "Could not find shared steps #{name.inspect}"
8
- instance_eval_with_args(*args, &shared_block)
8
+ instance_exec(*args, &shared_block)
9
9
  end
10
10
 
11
- def Given(message, options = {})
12
- RSpec.world.reporter.example_step_started(self, :given, message, options)
13
- if block_given? && !options[:pending]
14
- begin
15
- yield
16
- rescue Exception => e
17
- RSpec.world.reporter.example_step_failed(self, :given, message, options)
18
- raise e
19
- end
20
- RSpec.world.reporter.example_step_passed(self, :given, message, options)
21
- else
22
- RSpec.world.reporter.example_step_pending(self, :given, message, options)
23
- end
11
+ def Given(message, options = {}, &block)
12
+ RSpec.world.reporter.process_example_step(self, :given, message, options, &block)
24
13
  end
25
14
 
26
- def When(message, options = {})
27
- RSpec.world.reporter.example_step_started(self, :when, message, options)
28
- if block_given? && !options[:pending]
29
- begin
30
- yield
31
- rescue Exception => e
32
- RSpec.world.reporter.example_step_failed(self, :when, message, options)
33
- raise e
34
- end
35
- RSpec.world.reporter.example_step_passed(self, :when, message, options)
36
- else
37
- RSpec.world.reporter.example_step_pending(self, :when, message, options)
38
- end
15
+ def When(message, options = {}, &block)
16
+ RSpec.world.reporter.process_example_step(self, :when, message, options, &block)
39
17
  end
40
18
 
41
- def Then(message, options = {})
42
- RSpec.world.reporter.example_step_started(self, :then, message, options)
43
- if block_given? && !options[:pending]
44
- begin
45
- yield
46
- rescue Exception => e
47
- RSpec.world.reporter.example_step_failed(self, :then, message, options)
48
- raise e
49
- end
50
- RSpec.world.reporter.example_step_passed(self, :then, message, options)
51
- else
52
- RSpec.world.reporter.example_step_pending(self, :then, message, options)
53
- end
19
+ def Then(message, options = {}, &block)
20
+ RSpec.world.reporter.process_example_step(self, :then, message, options, &block)
54
21
  end
55
22
 
56
- def And(message, options = {})
57
- RSpec.world.reporter.example_step_started(self, :and, message, options)
58
- if block_given? && !options[:pending]
59
- begin
60
- yield
61
- rescue Exception => e
62
- RSpec.world.reporter.example_step_failed(self, :and, message, options)
63
- raise e
64
- end
65
- RSpec.world.reporter.example_step_passed(self, :and, message, options)
66
- else
67
- RSpec.world.reporter.example_step_pending(self, :and, message, options)
68
- end
23
+ def And(message, options = {}, &block)
24
+ RSpec.world.reporter.process_example_step(self, :and, message, options, &block)
69
25
  end
70
26
 
71
- def But(message, options = {})
72
- RSpec.world.reporter.example_step_started(self, :but, message, options)
73
- if block_given? && !options[:pending]
74
- begin
75
- yield
76
- rescue Exception => e
77
- RSpec.world.reporter.example_step_failed(self, :but, message, options)
78
- raise e
79
- end
80
- RSpec.world.reporter.example_step_passed(self, :but, message, options)
81
- else
82
- RSpec.world.reporter.example_step_pending(self, :but, message, options)
83
- end
27
+ def But(message, options = {}, &block)
28
+ RSpec.world.reporter.process_example_step(self, :but, message, options, &block)
84
29
  end
85
30
 
86
31
  end
@@ -0,0 +1,6 @@
1
+ module RSpec
2
+ module ExampleSteps
3
+ class Notification < Struct.new(:example, :type, :message, :options)
4
+ end
5
+ end
6
+ end
@@ -1,20 +1,44 @@
1
1
  module RSpec
2
2
  module ExampleSteps
3
3
  module Reporter
4
+ def process_example_step(example, type, message, options)
5
+ example_step_started(self, type, message, options)
6
+
7
+ if block_given? && !options[:pending]
8
+ begin
9
+ yield
10
+ rescue Exception => e
11
+ example_step_failed(self, type, message, options)
12
+ raise e
13
+ end
14
+ example_step_passed(self, type, message, options)
15
+ else
16
+ example_step_pending(self, type, message, options)
17
+ end
18
+ end
19
+
4
20
  def example_step_started(example, type, message, options)
5
- notify :example_step_started, example, type, message, options
21
+ notify :example_step_started, Notification.new(example, type, message, options)
6
22
  end
7
23
 
8
24
  def example_step_passed(example, type, message, options)
9
- notify :example_step_passed, example, type, message, options
25
+ notify :example_step_passed, Notification.new(example, type, message, options)
10
26
  end
11
27
 
12
28
  def example_step_pending(example, type, message, options)
13
- notify :example_step_pending, example, type, message, options
29
+ notify :example_step_pending, Notification.new(example, type, message, options)
14
30
  end
15
31
 
16
32
  def example_step_failed(example, type, message, options)
17
- notify :example_step_failed, example, type, message, options
33
+ notify :example_step_failed, Notification.new(example, type, message, options)
34
+ end
35
+
36
+ def registered_formatters
37
+ @listeners.values.map(&:to_a).flatten.uniq
38
+ end
39
+
40
+ def find_registered_formatter(klass)
41
+ registered_formatters.detect { |formatter| formatter.class == klass }
18
42
  end
19
43
  end
20
44
  end
@@ -2,19 +2,20 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "rspec-example_steps"
6
- s.version = "0.2.4"
7
- s.authors = ["Andriy Yanko"]
8
- s.email = ["andriy.yanko@gmail.com"]
9
- s.homepage = "https://github.com/railsware/rspec-example_steps"
5
+ s.name = 'rspec-example_steps'
6
+ s.version = '3.1.0'
7
+ s.authors = ['Andriy Yanko']
8
+ s.email = ['andriy.yanko@gmail.com']
9
+ s.homepage = 'https://github.com/railsware/rspec-example_steps'
10
10
  s.summary = %q{Given/When/Then steps for RSpec examples}
11
+ s.license = 'MIT'
11
12
 
12
- s.rubyforge_project = "rspec_example_steps"
13
+ s.rubyforge_project = 'rspec_example_steps'
13
14
 
14
15
  s.files = `git ls-files`.split("\n")
15
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = ["lib"]
18
+ s.require_paths = ['lib']
18
19
 
19
- s.add_runtime_dependency "rspec-core", ">2.0.0"
20
+ s.add_runtime_dependency 'rspec-core', '>=3.0.0'
20
21
  end
@@ -25,11 +25,11 @@ describe "example steps" do
25
25
  @but = "But value"
26
26
  end
27
27
 
28
- @thing.should == "Given value"
29
- @action.should == "When value"
30
- @result.should == "Then value"
31
- @and.should == "And value"
32
- @but.should == "But value"
28
+ expect(@thing).to eq("Given value")
29
+ expect(@action).to eq("When value")
30
+ expect(@result).to eq("Then value")
31
+ expect(@and).to eq("And value")
32
+ expect(@but).to eq("But value")
33
33
  end
34
34
  end
35
35
 
@@ -113,7 +113,7 @@ describe "example steps" do
113
113
 
114
114
  Steps "When fails" do
115
115
  When "action" do
116
- (2*2).should == 5
116
+ expect(2*2).to eq(5)
117
117
  end
118
118
 
119
119
  Then "I should see error" do
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Usual example' do
4
+ subject { 2 + 2 }
5
+
6
+ context 'success' do
7
+ specify { expect(subject).to eq(4) }
8
+ end
9
+
10
+ context 'failed' do
11
+ specify { expect(subject).to eq(5) }
12
+ end
13
+
14
+ context 'pending' do
15
+ it 'should be pending'
16
+ end
17
+ end
metadata CHANGED
@@ -1,80 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-example_steps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
5
- prerelease:
4
+ version: 3.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Andriy Yanko
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-18 00:00:00.000000000 Z
11
+ date: 2021-07-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec-core
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>'
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 2.0.0
19
+ version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>'
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 2.0.0
30
- description:
26
+ version: 3.0.0
27
+ description:
31
28
  email:
32
29
  - andriy.yanko@gmail.com
33
30
  executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
34
+ - ".gitignore"
35
+ - CHANGELOG.md
38
36
  - Gemfile
39
37
  - LICENSE
40
38
  - README.md
41
39
  - Rakefile
42
40
  - lib/rspec/example_steps.rb
43
- - lib/rspec/example_steps/base_formatter.rb
44
41
  - lib/rspec/example_steps/documentation_formatter.rb
45
42
  - lib/rspec/example_steps/example_group.rb
43
+ - lib/rspec/example_steps/notification.rb
46
44
  - lib/rspec/example_steps/reporter.rb
47
- - lib/rspec/example_steps/shared_steps.rb
48
45
  - lib/rspec/example_steps/world.rb
49
46
  - rspec-example_steps.gemspec
50
47
  - spec/example_steps_spec.rb
51
- - spec/shared_steps_spec.rb
48
+ - spec/regression_spec.rb
52
49
  - spec/spec_helper.rb
53
50
  homepage: https://github.com/railsware/rspec-example_steps
54
- licenses: []
55
- post_install_message:
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
56
55
  rdoc_options: []
57
56
  require_paths:
58
57
  - lib
59
58
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
59
  requirements:
62
- - - ! '>='
60
+ - - ">="
63
61
  - !ruby/object:Gem::Version
64
62
  version: '0'
65
63
  required_rubygems_version: !ruby/object:Gem::Requirement
66
- none: false
67
64
  requirements:
68
- - - ! '>='
65
+ - - ">="
69
66
  - !ruby/object:Gem::Version
70
67
  version: '0'
71
68
  requirements: []
72
- rubyforge_project: rspec_example_steps
73
- rubygems_version: 1.8.23
74
- signing_key:
75
- specification_version: 3
69
+ rubygems_version: 3.1.4
70
+ signing_key:
71
+ specification_version: 4
76
72
  summary: Given/When/Then steps for RSpec examples
77
73
  test_files:
78
74
  - spec/example_steps_spec.rb
79
- - spec/shared_steps_spec.rb
75
+ - spec/regression_spec.rb
80
76
  - spec/spec_helper.rb
@@ -1,17 +0,0 @@
1
- module RSpec
2
- module ExampleSteps
3
- module BaseFormatter
4
- def example_step_started(example, type, message, options)
5
- end
6
-
7
- def example_step_passed(example, type, message, options)
8
- end
9
-
10
- def example_step_pending(example, type, message, options)
11
- end
12
-
13
- def example_step_failed(example, type, message, options)
14
- end
15
- end
16
- end
17
- end
@@ -1,20 +0,0 @@
1
- module RSpec
2
- module ExampleSteps
3
- module SharedSteps
4
-
5
- def shared_steps(name, &block)
6
- ensure_shared_example_steps_name_not_taken(name)
7
- RSpec.world.shared_example_steps[name] = block
8
- end
9
-
10
- private
11
-
12
- def ensure_shared_example_steps_name_not_taken(name)
13
- if RSpec.world.shared_example_steps.has_key?(name)
14
- raise ArgumentError.new("Shared example steps '#{name}' already exists")
15
- end
16
- end
17
-
18
- end
19
- end
20
- end
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_steps "push steps" do
4
- Given "empty pipe" do
5
- pipe.clear
6
- end
7
-
8
- When "push data" do
9
- pipe.push "hello"
10
- end
11
-
12
- Then "pipe should have data" do
13
- pipe.items.should == ["hello"]
14
- end
15
- end
16
-
17
- shared_steps "push with arguments steps" do |value|
18
- When "push data" do
19
- pipe.push value
20
- end
21
- end
22
-
23
- shared_steps "pull steps" do
24
- When "pull data" do
25
- pipe.pull
26
- end
27
-
28
- Then "pipe should be empty" do
29
- pipe.items.should == []
30
- end
31
- end
32
-
33
- describe "shared steps" do
34
-
35
- let(:pipe) do
36
- Class.new do
37
- def initialize
38
- @values = []
39
- end
40
-
41
- def items
42
- @values
43
- end
44
-
45
- def clear
46
- @values = []
47
- end
48
-
49
- def push(value)
50
- @values << value
51
- end
52
-
53
- def pull
54
- @values.shift
55
- end
56
-
57
- end.new
58
- end
59
-
60
- Steps "push and pull steps" do
61
- include_steps "push steps"
62
- include_steps "pull steps"
63
- end
64
-
65
- Steps "push, count and pull" do
66
- include_steps "push steps"
67
- Then "pipe should have 1 item" do
68
- pipe.items.size.should == 1
69
- end
70
- include_steps "pull steps"
71
- end
72
-
73
- Steps "push with arguments and pull" do
74
- include_steps "push with arguments steps", "hi"
75
- pipe.items.should == ["hi"]
76
- include_steps "pull steps"
77
- end
78
- end