given_when_then 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +61 -57
- data/given_when_then.gemspec +1 -0
- data/lib/given_when_then.rb +0 -1
- data/lib/given_when_then/version.rb +2 -1
- data/spec/gwt_spec.rb +18 -0
- metadata +16 -4
data/README.md
CHANGED
@@ -1,86 +1,90 @@
|
|
1
|
-
|
1
|
+
# given_when_then
|
2
2
|
|
3
3
|
Use selected Cucumber-like syntax in your Rspec tests.
|
4
4
|
|
5
5
|
|
6
|
-
|
6
|
+
## Installation
|
7
7
|
|
8
|
-
In your Gemfile:
|
8
|
+
In your Gemfile, under the test group, specify:
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
group :test do
|
11
|
+
gem 'given_when_then'
|
12
|
+
# ...
|
13
|
+
end
|
14
14
|
|
15
|
+
And install with
|
15
16
|
|
16
|
-
|
17
|
+
bundle
|
17
18
|
|
18
|
-
If you'd love to use the Cucumber Given-When-Then mantra in your Rspec tests, just use it in place of the describe/it method calls like in this integration test:
|
19
19
|
|
20
|
-
|
21
|
-
Given 'there is a guest user' do
|
22
|
-
let(:user) { stub('user', :name => 'Mr XY', :email => 'xy@example.com', :password => 'secret' ) }
|
20
|
+
## Example Usage
|
23
21
|
|
24
|
-
|
25
|
-
before { visit root_path }
|
22
|
+
If you'd love to use the BDD Given-When-Then mantra in your Rspec tests, just use it in place of the describe/it method calls like in this sample integration test:
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
describe 'Signing up' do
|
25
|
+
Given 'there is a guest user' do
|
26
|
+
let(:user) { stub('user', :name => 'Mr XY', :email => 'xy@example.com', :password => 'secret' ) }
|
30
27
|
|
31
|
-
When 'he
|
32
|
-
before { visit
|
28
|
+
When 'he goes to the home page' do
|
29
|
+
before { visit root_path }
|
33
30
|
|
34
|
-
Then 'he should
|
35
|
-
page.should
|
31
|
+
Then 'he should see the navigational links' do
|
32
|
+
page.should have_content 'Sign up or Log in'
|
36
33
|
end
|
37
34
|
|
38
|
-
When 'he clicks the Sign up
|
39
|
-
|
40
|
-
click_button 'Sign up'
|
41
|
-
page.should have_content('errors prohibited')
|
42
|
-
User.count.should == 0
|
43
|
-
end
|
35
|
+
When 'he clicks the Sign up link' do
|
36
|
+
before { visit signup_path }
|
44
37
|
|
45
|
-
|
46
|
-
|
38
|
+
Then 'he should be presented with a signup form' do
|
39
|
+
page.should have_selector 'div[id="signup_form"]'
|
47
40
|
end
|
48
|
-
end
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
42
|
+
When 'he clicks the Sign up button without filling in his credentials' do
|
43
|
+
Then 'he should see an error message' do
|
44
|
+
click_button 'Sign up'
|
45
|
+
page.should have_content('errors prohibited')
|
46
|
+
User.count.should == 0
|
47
|
+
end
|
48
|
+
|
49
|
+
And 'the path to the form should be the signup_path (see routes.rb)' do
|
50
|
+
current_path.should == signup_path
|
51
|
+
end
|
57
52
|
end
|
58
53
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
When 'he fills the form with his credentials and clicks the Sign up button' do
|
55
|
+
before do
|
56
|
+
fill_in 'Name', :with => user.name
|
57
|
+
fill_in 'Email', :with => user.email
|
58
|
+
fill_in 'Password', :with => user.password
|
59
|
+
fill_in 'Confirm Password', :with => user.password
|
60
|
+
click_button 'Sign up'
|
61
|
+
end
|
62
|
+
|
63
|
+
Then 'he should be signed up successfully' do
|
64
|
+
page.should have_content('Signed up!')
|
65
|
+
current_path.should == root_path
|
66
|
+
User.count.should == 1
|
67
|
+
end
|
63
68
|
end
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
67
72
|
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
Then he should be signed up successfully
|
73
|
+
|
74
|
+
|
75
|
+
When you run the test with the -fs option, then in the case of success you get'll a nicely formatted output:
|
76
|
+
|
77
|
+
Signing up
|
78
|
+
Given there is a guest user
|
79
|
+
When he visits the home page
|
80
|
+
Then he should see the navigational links
|
81
|
+
When he clicks the Sign up link
|
82
|
+
Then he should be presented with a signup form
|
83
|
+
When he clicks the Sign up button without filling in his credentials
|
84
|
+
Then he should see an error message
|
85
|
+
And the path to the form should be the signup_path (see routes.rb)
|
86
|
+
When he fills the form with his credentials and clicks the Sign up button
|
87
|
+
Then he should be signed up successfully
|
84
88
|
|
85
89
|
|
86
90
|
Given and When are wrappers around Rspec's 'describe', while Then, And and Or wrap Rspec's 'it'.
|
data/given_when_then.gemspec
CHANGED
data/lib/given_when_then.rb
CHANGED
data/spec/gwt_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'given_when_then'
|
2
|
+
require 'rspec/core'
|
3
|
+
|
4
|
+
describe GivenWhenThen do
|
5
|
+
describe '#Given' do
|
6
|
+
it 'should be defined' do
|
7
|
+
lambda { RSpec::Core::ExampleGroup.Given }.should_not raise_exception(NoMethodError)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#Then' do
|
12
|
+
it 'should be an instance of RSpec::Core::Example' do
|
13
|
+
example_group = RSpec::Core::ExampleGroup.Given
|
14
|
+
example_group.Then('blah', lambda {}).should be_instance_of RSpec::Core::Example
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: given_when_then
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-core
|
16
|
-
requirement: &
|
16
|
+
requirement: &81673390 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,18 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *81673390
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &81673130 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *81673130
|
25
36
|
description: Use selected Cucumber-like syntax in your Rspec tests
|
26
37
|
email:
|
27
38
|
- marek.prihoda@gmail.com
|
@@ -36,6 +47,7 @@ files:
|
|
36
47
|
- given_when_then.gemspec
|
37
48
|
- lib/given_when_then.rb
|
38
49
|
- lib/given_when_then/version.rb
|
50
|
+
- spec/gwt_spec.rb
|
39
51
|
homepage: https://github.com/maprihoda/given_when_then
|
40
52
|
licenses: []
|
41
53
|
post_install_message:
|