bdd 0.0.1 → 0.0.2

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: 26bc9edd12abbfb44efd8697966b255f6c899347
4
- data.tar.gz: 8a9572f9e28559163428f23f78bb0a060f2512f3
3
+ metadata.gz: a4d91a1514792fd624df3de6f45e1a4d5491b7f7
4
+ data.tar.gz: 928c1fd5a8d6774004f6ef13eff6f9e028b4630f
5
5
  SHA512:
6
- metadata.gz: d7100c8e7cbfe604d8b15fe0a5db80008240e0ec32a163b79efd25e288657da4321052972f547eedae3655c7cae34bf6c468a777bf9866cf26839e708e65bdca
7
- data.tar.gz: 196f90b2f5b424220cbffe9e4a4cb490946b1a66b867b232168f82f546a300d760a5d8c41453399a5da29892203f97a59bdcd4ffc6b1ca596766282f2e671fda
6
+ metadata.gz: d6f14a84d66eb8a9f9fe002b15e9b6abb81cba9b4a32041c56aced89dc2cac6be6907e1d741d379a8ad22ff9ef958e5e8d5588bdc98415a0c0c0037c43b85985
7
+ data.tar.gz: f9a75ec22a3407dcd45b4e10ad4bf74d0cce51d42e499e2e728f5e8a7b524fbae3918e59c3a9857d02536a4be61fda5fcc01d5073c429bcff4bbfe0550d1f13c
data/.travis.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.5
3
6
  - 2.2.1
7
+ script: bundle exec rspec spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # CHANGELOG BY VERSION
2
+
3
+ ## IN PROGRESS
4
+
5
+ ### May 19th 2015
6
+
7
+ > @thejamespinto
8
+ - Removing dependency 'rspec-example_steps'
9
+ - No more need to have a .rspec with color and documentation format
10
+
11
+ ### May 20th 2015
12
+
13
+ > @thejamespinto
14
+ - renaming feature
15
+
16
+
17
+
18
+
19
+
20
+ ## v0.0.1
21
+
22
+ ### May 18th 2015
23
+
24
+ > @thejamespinto
25
+ - Renaming gem to 'bdd'
26
+
data/README.md CHANGED
@@ -1,43 +1,270 @@
1
- # Bdd
1
+ ## Bdd
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bdd`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Bdd brings cucumber-style Given/When/Then/And/But steps for RSpec examples
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ### Status
6
6
 
7
- ## Installation
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)
8
9
 
9
- Add this line to your application's Gemfile:
10
+ ### Description
11
+
12
+ This gem brings two major functionality to your tests
13
+
14
+ * Verbosity for rspec documentation formatter.
15
+ * Ability to comment or describe set of actions in example into some step.
16
+
17
+
18
+
19
+ ### Installation
10
20
 
11
21
  ```ruby
12
22
  gem 'bdd'
13
23
  ```
14
24
 
15
- And then execute:
25
+ Add to `spec/spec_helper.rb`
16
26
 
17
- $ bundle
27
+ ```ruby
28
+ require 'bdd'
29
+ ```
18
30
 
19
- Or install it yourself as:
20
31
 
21
- $ gem install bdd
22
32
 
23
- ## Usage
33
+ ### Example
24
34
 
25
- Add this to your spec_helper.rb file
35
+ `spec/features/search_spec.rb`
26
36
 
27
37
  ```ruby
28
- require 'bdd'
38
+ context 'Searching' do
39
+ it 'Result is found' do
40
+ Given 'I am on the search page' do
41
+ visit '/search'
42
+ expect(page).to have_content('Search')
43
+ end
44
+
45
+ When 'I search something' do
46
+ fill_in 'Search', with: 'John'
47
+ click_button 'Go'
48
+ end
49
+
50
+ Then 'I should see the word result' do
51
+ expect(page).to have_content('Result')
52
+ end
53
+ end
54
+ end
55
+ ```
56
+
57
+
58
+ ### Documentation formatting output:
59
+
60
+ `rspec -fd spec/features/search_spec.rb`
61
+
62
+ <pre>
63
+ <b>Searching</b>
64
+ <b>Result is found</b>
65
+ <b>Given</b> I am on the search page
66
+ <b> When</b> I search something
67
+ <b> Then</b> I should see the word result
68
+ </pre>
69
+
70
+
71
+
72
+ ### Shared Steps
73
+
74
+ ### Basic Example with shared steps
75
+
76
+ You can refactor steps into methods using plain Ruby syntax.
77
+
78
+ ```ruby
79
+ def given_I_log_in
80
+ Given "I log in" do
81
+ visit '/login'
82
+ fill_in 'Login', with: 'jack@example.com'
83
+ fill_in 'Password', with: 'password'
84
+ click_button "Log in"
85
+ expect(page).to have_content('Welcome jack@example.com')
86
+ end
87
+ end
88
+
89
+ def then_I_should_see_a_confirmation_message
90
+ Then "I should see a confirmation message" do
91
+ expect(page).to have_content('Your profile was updated successfully')
92
+ end
93
+ end
94
+
95
+ context 'User Flow' do
96
+ it 'User updates profile description' do
97
+ given_I_log_in
98
+ When 'I update profile description' do
99
+ ...
100
+ end
101
+ then_I_should_see_a_confirmation_message
102
+ end
103
+
104
+ it 'User updates profile avatar' do
105
+ given_I_log_in
106
+ When 'I update profile avatar' do
107
+ ...
108
+ end
109
+ then_I_should_see_a_confirmation_message
110
+ end
111
+ end
112
+ ```
113
+ Output:
114
+ <pre>
115
+ <b>User Flow</b>
116
+ <b>User updates profile description</b>
117
+ <b>Given</b> I log in
118
+ <b> When</b> I update profile description
119
+ <b> Then</b> I should see a confirmation message
120
+ </pre>
121
+
122
+
123
+ ### Nested Example with shared steps
124
+
125
+ Nesting will silence any output from the internal steps
126
+
127
+ ```ruby
128
+ def given_I_am_on_the_log_in_page
129
+ Given 'I am on the login page' do
130
+ visit '/login'
131
+ end
132
+ end
133
+
134
+ def when_I_submit_the_log_in_form
135
+ When 'I put credentials' do
136
+ fill_in 'Login', with: 'jack@example.com'
137
+ fill_in 'Password', with: 'password'
138
+ click_button "Log in"
139
+ end
140
+ end
141
+
142
+ def then_I_should_be_logged_in
143
+ Then 'I should be logged in' do
144
+ expect(page).to have_content('Welcome jack@example.com')
145
+ end
146
+ end
147
+
148
+ def given_I_log_in
149
+ Given "I log in" do
150
+ given_I_am_on_the_log_in_page
151
+ when_I_submit_the_log_in_form
152
+ then_I_should_be_logged_in
153
+ end
154
+ end
155
+
156
+ context 'User Flow' do
157
+ it 'User updates profile description' do
158
+ given_I_log_in
159
+ When 'I update profile description' do
160
+ ...
161
+ end
162
+ then_I_should_see_a_confirmation_message
163
+ end
164
+
165
+ it 'User updates profile avatar' do
166
+ given_I_log_in
167
+ When 'I update profile avatar' do
168
+ ...
169
+ end
170
+ then_I_should_see_a_confirmation_message
171
+ end
172
+ end
173
+ ```
174
+ Output:
175
+ <pre>
176
+ <b>User Flow</b>
177
+ <b>User updates profile description</b>
178
+ <b>Given</b> I log in
179
+ <b> When</b> I update profile description
180
+ <b> Then</b> I should see a confirmation message
181
+ </pre>
182
+
183
+
184
+ ### Renaming
185
+
186
+ Useful for refactored nesting, you can change a step's name
187
+
188
+ ```ruby
189
+ def when_I_log_in
190
+ When "I log in" do
191
+ visit '/login'
192
+ fill_in 'Login', with: 'jack@example.com'
193
+ fill_in 'Password', with: 'password'
194
+ click_button "Log in"
195
+ expect(page).to have_content('Welcome jack@example.com')
196
+ end
197
+ end
198
+
199
+
200
+ def given_I_log_in
201
+ Given when_I_log_in
202
+ end
203
+
204
+ context 'User Flow'
205
+ it 'User updates profile description' do
206
+ given_I_log_in
207
+ When 'I update profile description' do
208
+ ...
209
+ end
210
+ then_I_should_see_a_confirmation_message
211
+ end
212
+
213
+ it 'User updates profile avatar' do
214
+ given_I_log_in
215
+ When 'I update profile avatar' do
216
+ ...
217
+ end
218
+ then_I_should_see_a_confirmation_message
219
+ end
220
+ end
29
221
  ```
222
+ Output:
223
+ <pre>
224
+ <b>User Flow</b>
225
+ <b>User updates profile description</b>
226
+ <b>Given</b> I log in
227
+ <b> When</b> I update profile description
228
+ <b> Then</b> I should see a confirmation message
229
+ </pre>
230
+
231
+
232
+
233
+
234
+
235
+
30
236
 
31
237
  ## Development
32
238
 
33
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
239
+ Currently we only support __RSpec__
240
+
241
+ __minitest__ and __test_unit__ pull requests are wanted.
242
+
243
+ __internationalization__ pull requests are wanted.
244
+
245
+
246
+ ## Authors
247
+
248
+ * [James Pinto](http://github.com/thejamespinto)
249
+
34
250
 
35
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
251
 
37
252
  ## Contributing
38
253
 
39
- 1. Fork it ( https://github.com/[my-github-username]/bdd/fork )
254
+ 1. Fork it ( https://github.com/thejamespinto/bdd/fork )
40
255
  2. Create your feature branch (`git checkout -b my-new-feature`)
41
256
  3. Commit your changes (`git commit -am 'Add some feature'`)
42
257
  4. Push to the branch (`git push origin my-new-feature`)
43
258
  5. Create a new Pull Request
259
+
260
+ ## Alternatives and Inspiration
261
+
262
+ * [rspec-steps](https://github.com/LRDesign/rspec-steps)
263
+ * [rspec-given](https://github.com/jimweirich/rspec-given)
264
+ * [rspec-example_steps](https://github.com/railsware/rspec-example_steps)
265
+ * [cucumber](https://github.com/cucumber/cucumber)
266
+
267
+ <pre>
268
+ <b>rspec-steps</b>, <b>rspec-given</b> and <b>rspec-example_steps</b> run <i>AS</i> examples.
269
+ <b>bdd</b> and <b>cucumber</b> run <i>INSIDE</i> examples, running tests faster.
270
+ </pre>
data/bdd.gemspec CHANGED
@@ -21,13 +21,12 @@ Gem::Specification.new do |spec|
21
21
  # if spec.respond_to?(:metadata)
22
22
  # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
23
23
  # end
24
-
25
- spec.add_runtime_dependency 'rspec-example_steps'
24
+
26
25
  spec.add_runtime_dependency 'rspec'
27
26
  spec.add_runtime_dependency 'colorize'
28
27
 
29
28
 
30
- spec.add_development_dependency "bundler", "~> 1.9"
31
- spec.add_development_dependency "rake", "~> 10.0"
29
+ # spec.add_development_dependency "bundler", "~> 1.9"
30
+ # spec.add_development_dependency "rake", "~> 10.0"
32
31
  # spec.add_development_dependency 'rspec'
33
32
  end
@@ -1,83 +1,13 @@
1
1
  # https://raw.githubusercontent.com/rspec/rspec-core/v3.2.2/lib/rspec/core/formatters/documentation_formatter.rb
2
- # require "rspec/core/formatters/documentation_formatter"
3
2
 
4
3
  RSpec::Support.require_rspec_core "formatters/base_text_formatter"
5
4
 
6
- class RSpec::Core::ExampleGroup
7
- def step(msg)
8
- m = RSpec.current_example.metadata
9
-
10
- if block_given?
11
- # m[:step_messages] << msg #if m[:step_messages]
12
- if @is_during_rspec_step
13
- yield
14
- else
15
- m[:step_messages] << hash = {msg: msg}
16
- @is_during_rspec_step = true
17
- yield
18
- # apply green color if example passes
19
- hash[:color] = :green
20
- @is_during_rspec_step = false
21
- end
22
- else
23
- m[:step_messages] << {msg: "SKIPPED #{msg}"}
24
- end
25
- end
26
-
27
- def Given(msg, &block)
28
- step(["Given", msg], &block)
29
- end
30
-
31
- def When(msg, &block)
32
- step([" When", msg], &block)
33
- end
34
-
35
- def Then(msg, &block)
36
- step([" Then", msg], &block)
37
- end
38
-
39
- def And(msg, &block)
40
- step([" And", msg], &block)
41
- end
42
-
43
- def But(msg, &block)
44
- step([" But", msg], &block)
45
- end
46
-
47
- # def AndGiven(msg, &block)
48
- # step("And Given #{msg}", &block)
49
- # end
50
-
51
- # def AndWhen(msg, &block)
52
- # step(" And When #{msg}", &block)
53
- # end
54
-
55
- # def AndThen(msg, &block)
56
- # step(" And Then #{msg}", &block)
57
- # end
58
-
59
- # def ButGiven(msg, &block)
60
- # step("But Given #{msg}", &block)
61
- # end
62
-
63
- # def ButWhen(msg, &block)
64
- # step(" But When #{msg}", &block)
65
- # end
66
-
67
- # def ButThen(msg, &block)
68
- # step(" But Then #{msg}", &block)
69
- # end
70
- end
71
-
72
-
73
5
  module RSpec
74
6
  module Core
75
7
  module Formatters
8
+
76
9
  # @private
77
10
  class DocumentationFormatter < BaseTextFormatter
78
- Formatters.register self
79
- # , :example_group_started, :example_group_finished,
80
- # :example_passed, :example_pending, :example_failed
81
11
 
82
12
  def initialize(output)
83
13
  super
@@ -130,7 +60,6 @@ module RSpec
130
60
  else
131
61
  msg[0].light_white.bold
132
62
  end
133
- # msg0 = msg[0].white.bold
134
63
  last_step_title = msg[0]
135
64
 
136
65
  msg = [msg0, msg[1].colorize(color)].join(' ')
@@ -138,8 +67,6 @@ module RSpec
138
67
  # light_black doesn't really get used because the test failure prevents other messages from being added
139
68
  r = [next_indentation, msg]
140
69
  r.join(' ')
141
- # r = [next_indentation, "-".colorize(color), msg]
142
- # r.join(' ').colorize(color)
143
70
  end
144
71
  end
145
72
 
@@ -147,12 +74,6 @@ module RSpec
147
74
  " "
148
75
  end
149
76
 
150
-
151
- def next_failure_index
152
- @next_failure_index ||= 0
153
- @next_failure_index += 1
154
- end
155
-
156
77
  def current_indentation
157
78
  ' ' * @group_level
158
79
  end
@@ -161,9 +82,6 @@ module RSpec
161
82
  ' ' * (@group_level+1)
162
83
  end
163
84
 
164
- def example_group_chain
165
- example_group.parent_groups.reverse
166
- end
167
85
  end
168
86
  end
169
87
  end
@@ -0,0 +1,79 @@
1
+ module Bdd
2
+ module RSpec
3
+ module ExampleGroup
4
+
5
+
6
+ def step(array, &block)
7
+ m = ::RSpec.current_example.metadata
8
+ step_messages = m[:step_messages]
9
+
10
+ if block_given?
11
+ # m[:step_messages] << array #if m[:step_messages]
12
+ if @is_during_rspec_step
13
+ yield
14
+ else
15
+ step_messages << hash = {msg: array}
16
+ @is_during_rspec_step = true
17
+ yield
18
+ # apply green color if example passes
19
+ hash[:color] = :green
20
+ @is_during_rspec_step = false
21
+ end
22
+
23
+ elsif array.last == :bdd
24
+ a = step_messages.last[:msg]
25
+ a[0] = array[0]
26
+ else
27
+ step_messages << {msg: "SKIPPED #{array}"}
28
+ end
29
+ return :bdd
30
+ end
31
+
32
+ def Given(msg, &block)
33
+ step(["Given", msg], &block)
34
+ end
35
+
36
+ def When(msg, &block)
37
+ step([" When", msg], &block)
38
+ end
39
+
40
+ def Then(msg, &block)
41
+ step([" Then", msg], &block)
42
+ end
43
+
44
+ def And(msg, &block)
45
+ step([" And", msg], &block)
46
+ end
47
+
48
+ def But(msg, &block)
49
+ step([" But", msg], &block)
50
+ end
51
+
52
+ # def AndGiven(msg, &block)
53
+ # step("And Given #{msg}", &block)
54
+ # end
55
+
56
+ # def AndWhen(msg, &block)
57
+ # step(" And When #{msg}", &block)
58
+ # end
59
+
60
+ # def AndThen(msg, &block)
61
+ # step(" And Then #{msg}", &block)
62
+ # end
63
+
64
+ # def ButGiven(msg, &block)
65
+ # step("But Given #{msg}", &block)
66
+ # end
67
+
68
+ # def ButWhen(msg, &block)
69
+ # step(" But When #{msg}", &block)
70
+ # end
71
+
72
+ # def ButThen(msg, &block)
73
+ # step(" But Then #{msg}", &block)
74
+ # end
75
+
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,15 @@
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
data/lib/bdd/rspec.rb CHANGED
@@ -1,8 +1,37 @@
1
- require "rspec/example_steps"
2
- require "bdd/rspec/code"
1
+ require 'bdd/rspec/reporter'
2
+ require 'bdd/rspec/example_group'
3
+ require 'bdd/rspec/documentation_formatter'
3
4
 
4
- module Bdd
5
- module RSpec
6
- # Your code goes here...
7
- end
5
+ RSpec::Core::Reporter.send :include, Bdd::RSpec::Reporter
6
+ 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
8
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.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/bdd.rb CHANGED
@@ -4,7 +4,7 @@ require "colorize"
4
4
 
5
5
 
6
6
 
7
- require "bdd/rspec" # if defined? ::RSpec
7
+ require "bdd/rspec" if defined? RSpec
8
8
  # TODO: require "bdd/test_unit" # if
9
9
  # TODO: require "bdd/minitest" # if
10
10
 
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-05-18 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rspec-example_steps
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rspec
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,34 +38,6 @@ dependencies:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.9'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.9'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '10.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '10.0'
83
41
  description: Cucumber style in your RSpec tests
84
42
  email:
85
43
  - thejamespinto@gmail.com
@@ -88,8 +46,8 @@ extensions: []
88
46
  extra_rdoc_files: []
89
47
  files:
90
48
  - ".gitignore"
91
- - ".rspec"
92
49
  - ".travis.yml"
50
+ - CHANGELOG.md
93
51
  - Gemfile
94
52
  - README.md
95
53
  - Rakefile
@@ -98,7 +56,9 @@ files:
98
56
  - bin/setup
99
57
  - lib/bdd.rb
100
58
  - lib/bdd/rspec.rb
101
- - lib/bdd/rspec/code.rb
59
+ - lib/bdd/rspec/documentation_formatter.rb
60
+ - lib/bdd/rspec/example_group.rb
61
+ - lib/bdd/rspec/reporter.rb
102
62
  - lib/bdd/version.rb
103
63
  homepage: https://github.com/thejamespinto/bdd
104
64
  licenses: []
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color