bdd 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4d91a1514792fd624df3de6f45e1a4d5491b7f7
4
- data.tar.gz: 928c1fd5a8d6774004f6ef13eff6f9e028b4630f
3
+ metadata.gz: 7b3071c8c5074b6bca6bdd82ba09c81b9db354e5
4
+ data.tar.gz: 45901f145dd5e74fa4afed0dd81e921211068b59
5
5
  SHA512:
6
- metadata.gz: d6f14a84d66eb8a9f9fe002b15e9b6abb81cba9b4a32041c56aced89dc2cac6be6907e1d741d379a8ad22ff9ef958e5e8d5588bdc98415a0c0c0037c43b85985
7
- data.tar.gz: f9a75ec22a3407dcd45b4e10ad4bf74d0cce51d42e499e2e728f5e8a7b524fbae3918e59c3a9857d02536a4be61fda5fcc01d5073c429bcff4bbfe0550d1f13c
6
+ metadata.gz: f75dff103d304b7113f40aee32b9ed767e5665ea1f729a6bea763a5122566e865098f357fc0dd95a7472fec66fb74bffcc25b65c82238782367ce58bcc0425f1
7
+ data.tar.gz: 472fdb4a93f13e82a6c3f7ee396f091f180f6c8ac590027232406d8cd453ad9fddef2cba6fadd442692506fbc919460e0ee76970aef44dde496235367b8ffe20
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## IN PROGRESS
4
4
 
5
+ ### June 17th 2015
6
+
7
+ > @rafaelsales
8
+ - Does not force BDD formatting when gem is included in Gemfile
9
+ To use BDD Formatter follow steps in installation section of README
10
+ - Remove monkey patch of RSpec documentation formatter
11
+
5
12
  ### May 19th 2015
6
13
 
7
14
  > @thejamespinto
data/README.md CHANGED
@@ -4,8 +4,16 @@ Bdd brings cucumber-style Given/When/Then/And/But steps for RSpec examples
4
4
 
5
5
  ### Status
6
6
 
7
- [![Gem Version](https://badge.fury.io/rb/bdd.svg)](http://badge.fury.io/rb/bdd)
8
- [![Build Status](https://travis-ci.org/thejamespinto/bdd.svg)](https://travis-ci.org/thejamespinto/bdd)
7
+ | Master | Gem Version |
8
+ | :----: | :----: |
9
+ | [![Master Build Status](https://img.shields.io/travis/thejamespinto/bdd.svg)](https://travis-ci.org/thejamespinto/bdd) | [![Gem Version](https://img.shields.io/gem/v/bdd.svg)](https://rubygems.org/gems/bdd) |
10
+
11
+
12
+ [![GitHub License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://rubygems.org/gems/bdd)
13
+ [![Gem Downloads](http://img.shields.io/gem/dt/bdd.svg)](https://rubygems.org/gems/bdd)
14
+ [![GitHub Issues](https://img.shields.io/github/issues/thejamespinto/bdd.svg)](https://rubygems.org/gems/bdd)
15
+
16
+
9
17
 
10
18
  ### Description
11
19
 
@@ -16,21 +24,34 @@ This gem brings two major functionality to your tests
16
24
 
17
25
 
18
26
 
19
- ### Installation
27
+ ## Installation
28
+
29
+ Include in your Gemfile:
20
30
 
21
31
  ```ruby
22
- gem 'bdd'
32
+ group :test do
33
+ gem 'bdd'
34
+ end
23
35
  ```
24
36
 
25
- Add to `spec/spec_helper.rb`
37
+ ### RSpec
26
38
 
27
- ```ruby
28
- require 'bdd'
29
- ```
39
+ Run specs with custom format specified inline:
40
+
41
+ `
42
+ rspec --format Bdd::RSpec::Formatter --color spec
43
+ `
30
44
 
45
+ Or, if you want to use as your default formatter, simply put the options in your .rspec file:
31
46
 
47
+ `.rspec`
48
+
49
+ ```yml
50
+ --format Bdd::RSpec::Formatter
51
+ --color
52
+ ```
32
53
 
33
- ### Example
54
+ ## Output Example
34
55
 
35
56
  `spec/features/search_spec.rb`
36
57
 
@@ -2,13 +2,13 @@ module Bdd
2
2
  module RSpec
3
3
  module ExampleGroup
4
4
 
5
-
6
5
  def step(array, &block)
7
- m = ::RSpec.current_example.metadata
8
- step_messages = m[:step_messages]
9
-
6
+ unless using_bdd_formatter?
7
+ yield if block_given?
8
+ return
9
+ end
10
+
10
11
  if block_given?
11
- # m[:step_messages] << array #if m[:step_messages]
12
12
  if @is_during_rspec_step
13
13
  yield
14
14
  else
@@ -74,6 +74,15 @@ module Bdd
74
74
  # end
75
75
 
76
76
 
77
+ private
78
+
79
+ def step_messages
80
+ ::RSpec.current_example.metadata[:step_messages]
81
+ end
82
+
83
+ def using_bdd_formatter?
84
+ !step_messages.nil?
85
+ end
77
86
  end
78
87
  end
79
88
  end
@@ -0,0 +1,63 @@
1
+ RSpec::Support.require_rspec_core "formatters/documentation_formatter"
2
+
3
+ module Bdd
4
+ module RSpec
5
+ class Formatter < ::RSpec::Core::Formatters::DocumentationFormatter
6
+
7
+ ::RSpec::Core::Formatters.register self, :example_group_started, :example_group_finished,
8
+ :example_started, :example_passed,
9
+ :example_pending, :example_failed
10
+
11
+ def example_started(notification)
12
+ notification.example.metadata[:step_messages] = []
13
+ end
14
+
15
+ def example_passed(passed)
16
+ super
17
+ output.puts read_steps(passed.example)
18
+ end
19
+
20
+ def example_pending(pending)
21
+ super
22
+ output.puts read_steps(pending.example, :yellow)
23
+ end
24
+
25
+ def example_failed(failure)
26
+ super
27
+ output.puts read_steps(failure.example, :red)
28
+ end
29
+
30
+ private
31
+
32
+ def read_steps(example, color2=nil)
33
+ last_step_title = ""
34
+ example.metadata[:step_messages].map do |hash|
35
+ msg = hash[:msg]
36
+ color = hash[:color] || color2 || :light_black
37
+ if msg.is_a? Array
38
+ msg0 = if msg[0] == last_step_title
39
+ blank_step_title
40
+ else
41
+ msg[0].light_white.bold
42
+ end
43
+ last_step_title = msg[0]
44
+
45
+ msg = [msg0, msg[1].colorize(color)].join(' ')
46
+ end
47
+ # light_black doesn't really get used because the test failure prevents other messages from being added
48
+ r = [next_indentation, msg]
49
+ r.join(' ')
50
+ end
51
+ end
52
+
53
+ def blank_step_title
54
+ " "
55
+ end
56
+
57
+ def next_indentation
58
+ ' ' * (@group_level+1)
59
+ end
60
+
61
+ end
62
+ end
63
+ end
data/lib/bdd/rspec.rb CHANGED
@@ -1,37 +1,3 @@
1
- require 'bdd/rspec/reporter'
2
1
  require 'bdd/rspec/example_group'
3
- require 'bdd/rspec/documentation_formatter'
4
2
 
5
- RSpec::Core::Reporter.send :include, Bdd::RSpec::Reporter
6
3
  RSpec::Core::ExampleGroup.send :include, Bdd::RSpec::ExampleGroup
7
-
8
-
9
-
10
- #
11
- # CONFIGURE
12
- #
13
- RSpec.configure do |config|
14
- # Use color in STDOUT
15
- config.color = true
16
-
17
- # Use color not only in STDOUT but also in pagers and files
18
- config.tty = true
19
-
20
- # Use the specified formatter
21
- config.formatter = :documentation # :progress, :html, :textmate
22
- end
23
-
24
-
25
-
26
- #
27
- # REGISTER
28
- #
29
-
30
- # if formatter = RSpec.world.reporter.__bdd_find_registered_formatter(RSpec::Core::Formatters::DocumentationFormatter)
31
- # RSpec.world.reporter.register_listener formatter, :example_started
32
- # RSpec::Core::Formatters.register formatter
33
- # end
34
-
35
- formatter = RSpec::Core::Formatters::DocumentationFormatter.new($stdout)
36
- RSpec.world.reporter.register_listener formatter, :example_started
37
- RSpec::Core::Formatters.register formatter
data/lib/bdd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bdd
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Pinto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -56,9 +56,8 @@ files:
56
56
  - bin/setup
57
57
  - lib/bdd.rb
58
58
  - lib/bdd/rspec.rb
59
- - lib/bdd/rspec/documentation_formatter.rb
60
59
  - lib/bdd/rspec/example_group.rb
61
- - lib/bdd/rspec/reporter.rb
60
+ - lib/bdd/rspec/formatter.rb
62
61
  - lib/bdd/version.rb
63
62
  homepage: https://github.com/thejamespinto/bdd
64
63
  licenses: []
@@ -1,88 +0,0 @@
1
- # https://raw.githubusercontent.com/rspec/rspec-core/v3.2.2/lib/rspec/core/formatters/documentation_formatter.rb
2
-
3
- RSpec::Support.require_rspec_core "formatters/base_text_formatter"
4
-
5
- module RSpec
6
- module Core
7
- module Formatters
8
-
9
- # @private
10
- class DocumentationFormatter < BaseTextFormatter
11
-
12
- def initialize(output)
13
- super
14
- @group_level = 0
15
- end
16
-
17
-
18
- def example_started(notification)
19
- notification.example.metadata[:step_messages] = []
20
- end
21
-
22
- def example_group_started(notification)
23
- output.puts if @group_level == 0
24
- output.puts "#{current_indentation}#{notification.group.description.strip}"
25
-
26
- @group_level += 1
27
- end
28
-
29
- def example_group_finished(_notification)
30
- @group_level -= 1
31
- end
32
-
33
- def example_passed(passed)
34
- output.puts passed_output(passed.example)
35
- output.puts read_steps(passed.example)
36
- end
37
-
38
- def example_pending(pending)
39
- output.puts pending_output(pending.example,
40
- pending.example.execution_result.pending_message)
41
- output.puts read_steps(pending.example, :yellow)
42
- end
43
-
44
- def example_failed(failure)
45
- output.puts failure_output(failure.example,
46
- failure.example.execution_result.exception)
47
- output.puts read_steps(failure.example, :red)
48
- end
49
-
50
- private
51
-
52
- def read_steps(example, color2=nil)
53
- last_step_title = ""
54
- example.metadata[:step_messages].map do |hash|
55
- msg = hash[:msg]
56
- color = hash[:color] || color2 || :light_black
57
- if msg.is_a? Array
58
- msg0 = if msg[0] == last_step_title
59
- blank_step_title
60
- else
61
- msg[0].light_white.bold
62
- end
63
- last_step_title = msg[0]
64
-
65
- msg = [msg0, msg[1].colorize(color)].join(' ')
66
- end
67
- # light_black doesn't really get used because the test failure prevents other messages from being added
68
- r = [next_indentation, msg]
69
- r.join(' ')
70
- end
71
- end
72
-
73
- def blank_step_title
74
- " "
75
- end
76
-
77
- def current_indentation
78
- ' ' * @group_level
79
- end
80
-
81
- def next_indentation
82
- ' ' * (@group_level+1)
83
- end
84
-
85
- end
86
- end
87
- end
88
- end
@@ -1,15 +0,0 @@
1
- module Bdd
2
- module RSpec
3
- module Reporter
4
-
5
- def __bdd_registered_formatters
6
- @listeners.values.map(&:to_a).flatten.uniq
7
- end
8
-
9
- def __bdd_find_registered_formatter(klass)
10
- __bdd_registered_formatters.detect { |formatter| formatter.class == klass }
11
- end
12
-
13
- end
14
- end
15
- end