rspec-example_steps 0.2.5 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 560058d2eeca41408e0cc1bf55c6b179b6373dc9
4
- data.tar.gz: 3840525830d82be9f0ba1195ab9ee35d60bb8af3
3
+ metadata.gz: c7115307b34165ae0ecd94334e446522262ed4ac
4
+ data.tar.gz: 0d463def26a2172e776ea63a5fd33c7563544189
5
5
  SHA512:
6
- metadata.gz: 4b1e922a5b487ed69466a392c642ffb6fcc08e2a011bfded641b575669adde8191677d6b8b8208caeb52639cc246ce722724cb72b67fac518cda65c1227a611f
7
- data.tar.gz: 9d86dff6f94cb42bd9ab53a208f7356e01c282f9796026eb18a172c59037286ec0e14d39072a5970d37a84155cb5108ef9cf00ef8e12ed8a4a5dc1006509e761
6
+ metadata.gz: 24ce0f375bf74970c8ad4310b0a07534200183664aaca22dd1f448a291cea69721513079fe4017eba5943073215f6ae8dabb2fb8170dfb603997e370963f41a1
7
+ data.tar.gz: cd911247e763fae0a5cd2b5d65a2a74fdb716cd949ed8a8b4eb0cabeeba2fa9fd46dd93001c03571f7b7baa0080d49af639fedffea467178ea035c913c65a215
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rspec', '2.14.0'
5
+ gem 'rspec', '3.0.0.rc1'
data/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Given/When/Then/And/But steps for RSpec examples
4
4
 
5
+ ### Installation
6
+
7
+ * For rspec v2 use gem v0.2.x or branch rspec2
8
+ * For rspec v3 user gem v3.x.x or master
9
+
10
+ gem 'rspec-example_steps'
11
+
5
12
  ### Example
6
13
 
7
14
  require 'rspec/example_steps'
@@ -121,12 +128,12 @@ Simular to Example :pending behavior:
121
128
 
122
129
  # pass :pending => true option
123
130
  Then "I should see welcome", :pending => true do
124
- ...
131
+ ...
125
132
  end
126
133
 
127
134
  # pass :pending => "some pending message"
128
135
  Then "I should see last login IP", :pending => "WIP" do
129
- ...
136
+ ...
130
137
  end
131
138
  end
132
139
 
@@ -1,26 +1,27 @@
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
20
+ RSpec::Core::ExampleGroup.define_example_method :Steps, with_steps: true
21
+
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
24
25
  end
25
26
 
26
27
  require 'rspec/example_steps/shared_steps'
@@ -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.example) 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,29 +1,44 @@
1
1
  module RSpec
2
2
  module ExampleSteps
3
3
  module Reporter
4
- def self.included(base)
5
- base::NOTIFICATIONS.push(
6
- :example_step_started,
7
- :example_step_passed,
8
- :example_step_pending,
9
- :example_step_failed
10
- ) if base.constants.include?(:NOTIFICATIONS)
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
11
18
  end
12
19
 
13
20
  def example_step_started(example, type, message, options)
14
- notify :example_step_started, example, type, message, options
21
+ notify :example_step_started, Notification.new(example, type, message, options)
15
22
  end
16
23
 
17
24
  def example_step_passed(example, type, message, options)
18
- notify :example_step_passed, example, type, message, options
25
+ notify :example_step_passed, Notification.new(example, type, message, options)
19
26
  end
20
27
 
21
28
  def example_step_pending(example, type, message, options)
22
- notify :example_step_pending, example, type, message, options
29
+ notify :example_step_pending, Notification.new(example, type, message, options)
23
30
  end
24
31
 
25
32
  def example_step_failed(example, type, message, options)
26
- 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 }
27
42
  end
28
43
  end
29
44
  end
@@ -6,7 +6,7 @@ module RSpec
6
6
  ensure_shared_example_steps_name_not_taken(name)
7
7
  RSpec.world.shared_example_steps[name] = block
8
8
  end
9
-
9
+
10
10
  private
11
11
 
12
12
  def ensure_shared_example_steps_name_not_taken(name)
@@ -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.5"
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.0.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.rc1'
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
@@ -10,7 +10,7 @@ shared_steps "push steps" do
10
10
  end
11
11
 
12
12
  Then "pipe should have data" do
13
- pipe.items.should == ["hello"]
13
+ expect(pipe.items).to eq(["hello"])
14
14
  end
15
15
  end
16
16
 
@@ -26,7 +26,7 @@ shared_steps "pull steps" do
26
26
  end
27
27
 
28
28
  Then "pipe should be empty" do
29
- pipe.items.should == []
29
+ expect(pipe.items).to eq([])
30
30
  end
31
31
  end
32
32
 
@@ -65,14 +65,14 @@ describe "shared steps" do
65
65
  Steps "push, count and pull" do
66
66
  include_steps "push steps"
67
67
  Then "pipe should have 1 item" do
68
- pipe.items.size.should == 1
68
+ expect(pipe.items.size).to eq(1)
69
69
  end
70
70
  include_steps "pull steps"
71
71
  end
72
72
 
73
73
  Steps "push with arguments and pull" do
74
74
  include_steps "push with arguments steps", "hi"
75
- pipe.items.should == ["hi"]
75
+ expect(pipe.items).to eq(["hi"])
76
76
  include_steps "pull steps"
77
77
  end
78
78
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-example_steps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andriy Yanko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-29 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>'
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: 3.0.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>'
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0
26
+ version: 3.0.0.rc1
27
27
  description:
28
28
  email:
29
29
  - andriy.yanko@gmail.com
@@ -31,15 +31,15 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - .gitignore
34
+ - ".gitignore"
35
35
  - Gemfile
36
36
  - LICENSE
37
37
  - README.md
38
38
  - Rakefile
39
39
  - lib/rspec/example_steps.rb
40
- - lib/rspec/example_steps/base_formatter.rb
41
40
  - lib/rspec/example_steps/documentation_formatter.rb
42
41
  - lib/rspec/example_steps/example_group.rb
42
+ - lib/rspec/example_steps/notification.rb
43
43
  - lib/rspec/example_steps/reporter.rb
44
44
  - lib/rspec/example_steps/shared_steps.rb
45
45
  - lib/rspec/example_steps/world.rb
@@ -48,7 +48,8 @@ files:
48
48
  - spec/shared_steps_spec.rb
49
49
  - spec/spec_helper.rb
50
50
  homepage: https://github.com/railsware/rspec-example_steps
51
- licenses: []
51
+ licenses:
52
+ - MIT
52
53
  metadata: {}
53
54
  post_install_message:
54
55
  rdoc_options: []
@@ -56,17 +57,17 @@ require_paths:
56
57
  - lib
57
58
  required_ruby_version: !ruby/object:Gem::Requirement
58
59
  requirements:
59
- - - '>='
60
+ - - ">="
60
61
  - !ruby/object:Gem::Version
61
62
  version: '0'
62
63
  required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  requirements:
64
- - - '>='
65
+ - - ">="
65
66
  - !ruby/object:Gem::Version
66
67
  version: '0'
67
68
  requirements: []
68
69
  rubyforge_project: rspec_example_steps
69
- rubygems_version: 2.0.3
70
+ rubygems_version: 2.2.2
70
71
  signing_key:
71
72
  specification_version: 4
72
73
  summary: Given/When/Then steps for RSpec examples
@@ -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