given_when_then 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ TODO.txt
6
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in given_when_then.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ == given_when_then
2
+
3
+ Use selected Cucumber-like syntax in your Rspec tests.
4
+
5
+
6
+ == Installation
7
+
8
+ In your Gemfile:
9
+
10
+ group :test do
11
+ gem 'given_when_then'
12
+ # ...
13
+ end
14
+
15
+
16
+ == Usage
17
+
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
+
20
+ describe 'Signing up' do
21
+ Given 'there is a guest user' do
22
+ let(:user) { stub('user', :name => 'Mr XY', :email => 'xy@example.com', :password => 'secret' ) }
23
+
24
+ When 'he goes the home page' do
25
+ before { visit root_path }
26
+
27
+ Then 'he should see the navigational links' do
28
+ page.should have_content 'Sign up or Log in'
29
+ end
30
+
31
+ When 'he clicks the Sign up link' do
32
+ before { visit signup_path }
33
+
34
+ Then 'he should be presented with a signup form' do
35
+ page.should have_selector 'div[id="signup_form"]'
36
+ end
37
+
38
+ When 'he clicks the Sign up button without filling in his credentials' do
39
+ Then 'he should see an error message' do
40
+ click_button 'Sign up'
41
+ page.should have_content('errors prohibited')
42
+ User.count.should == 0
43
+ end
44
+
45
+ And 'the path to the form should be the signup_path (see routes.rb)' do
46
+ current_path.should == signup_path
47
+ end
48
+ end
49
+
50
+ When 'he fills the form with his credentials and clicks the Sign up button' do
51
+ before do
52
+ fill_in 'Name', :with => user.name
53
+ fill_in 'Email', :with => user.email
54
+ fill_in 'Password', :with => user.password
55
+ fill_in 'Confirm Password', :with => user.password
56
+ click_button 'Sign up'
57
+ end
58
+
59
+ Then 'he should be signed up successfully' do
60
+ page.should have_content('Signed up!')
61
+ current_path.should == root_path
62
+ User.count.should == 1
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+
71
+ When you run the test with -fs, then in case of success you get a nicely formatted output:
72
+
73
+ Signing up
74
+ Given there is a guest user
75
+ When he visits the home page
76
+ Then he should see the navigational links
77
+ When he clicks the Sign up link
78
+ Then he should be presented with a signup form
79
+ When he clicks the Sign up button without filling in his credentials
80
+ Then he should see an error message
81
+ And the path to the form should be the signup_path (see routes.rb)
82
+ When he fills the form with his credentials and clicks the Sign up button
83
+ Then he should be signed up successfully
84
+
85
+
86
+ Given and When are wrappers around Rspec's 'describe', while Then, And and Or wrap Rspec's 'it'.
87
+ There's no Scenario or Feature because this is Rspec, not Cucumber.
88
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "given_when_then/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "given_when_then"
7
+ s.version = GivenWhenThen::VERSION
8
+ s.authors = ["Marek Prihoda"]
9
+ s.email = ["marek.prihoda@gmail.com"]
10
+ s.homepage = "https://github.com/maprihoda/given_when_then"
11
+ s.summary = %q{Use selected Cucumber-like syntax in your Rspec tests}
12
+ s.description = %q{Use selected Cucumber-like syntax in your Rspec tests}
13
+
14
+ s.rubyforge_project = "given_when_then"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency "rspec-core"
20
+ end
21
+
@@ -0,0 +1,28 @@
1
+ require "rspec/core"
2
+ require "given_when_then/version"
3
+
4
+ module GivenWhenThen
5
+
6
+ class RSpec::Core::ExampleGroup
7
+ class << self
8
+ %w(Given When).each do |m|
9
+ class_eval do
10
+ define_method(m) do |*args, &block|
11
+ describe(m, *args, &block)
12
+ end
13
+ end
14
+ end
15
+
16
+ %w(Then And Or).each do |m|
17
+ class_eval do
18
+ define_method(m) do |*args, &block|
19
+ args[0] = "#{m} " + args[0]
20
+ it(*args, &block)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,3 @@
1
+ module GivenWhenThen
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: given_when_then
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marek Prihoda
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec-core
16
+ requirement: &82834160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *82834160
25
+ description: Use selected Cucumber-like syntax in your Rspec tests
26
+ email:
27
+ - marek.prihoda@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - given_when_then.gemspec
37
+ - lib/given_when_then.rb
38
+ - lib/given_when_then/version.rb
39
+ homepage: https://github.com/maprihoda/given_when_then
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project: given_when_then
59
+ rubygems_version: 1.8.11
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Use selected Cucumber-like syntax in your Rspec tests
63
+ test_files: []