scenario 0.2.0 → 0.3.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.
- data/README.markdown +66 -60
- data/VERSION +1 -1
- data/lib/scenario/rspec.rb +13 -19
- data/lib/scenario/scenario.rb +7 -5
- data/scenario.gemspec +2 -2
- data/spec/scenario_spec.rb +11 -45
- data/spec/scenarios/test_scenarios.rb +10 -28
- metadata +4 -4
data/README.markdown
CHANGED
@@ -1,92 +1,97 @@
|
|
1
1
|
Scenario
|
2
2
|
========
|
3
3
|
|
4
|
-
|
5
|
-
block or by passing in a Module (or even both).
|
4
|
+
Scenarios is a super-simple way to move common setup and helper methods into cohesive "scenarios" that can be included easily in your specs. The advantage of a scenario over regular mixin modules is that you can use RSpec hooks (eg. `before :each {}`) to do the setup instead of having redundant, copy-pasted setup littering your specs.
|
6
5
|
|
7
|
-
|
6
|
+
Examples
|
7
|
+
--------
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
|
11
|
-
define :setup_user do |name|
|
12
|
-
User.create( :name => name, :admin => true )
|
13
|
-
end
|
14
|
-
end
|
10
|
+
# Describe your scenarios:
|
15
11
|
|
16
|
-
|
17
|
-
|
12
|
+
describe_scenario :user do
|
13
|
+
before :all do
|
14
|
+
@user = User.create( :name => "Bob", :password => "foo", :admin => false )
|
15
|
+
end
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
module AdminMethods
|
27
|
-
def setup_user( name )
|
28
|
-
User.create( :name => name, :admin => true )
|
17
|
+
def login
|
18
|
+
visit( url( :login ) )
|
19
|
+
fill_in :name, :with => "Bob"
|
20
|
+
fill_in :password, :with => "foo"
|
21
|
+
click_button "Login"
|
22
|
+
response
|
29
23
|
end
|
30
24
|
end
|
31
25
|
|
32
|
-
describe_scenario :admin
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
describe_scenario :admin do
|
27
|
+
before :all do
|
28
|
+
@user = User.create( :name => "Sally", :password => "bar", :admin => true )
|
29
|
+
end
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
module AdminMethods
|
45
|
-
def setup_user( name )
|
46
|
-
User.create( :name => name, :admin => true )
|
31
|
+
def login
|
32
|
+
visit( url( :login ) )
|
33
|
+
fill_in :name, :with => "Sally"
|
34
|
+
fill_in :password, :with => "bar"
|
35
|
+
click_button "Login"
|
36
|
+
response
|
47
37
|
end
|
48
38
|
end
|
49
39
|
|
50
|
-
|
51
|
-
define :admin?( user )
|
52
|
-
user.admin == true
|
53
|
-
end
|
54
|
-
end
|
40
|
+
# Write your specs:
|
55
41
|
|
56
|
-
describe "
|
57
|
-
|
42
|
+
describe "Logging in" do
|
43
|
+
describe "as an user" do
|
44
|
+
scenario :user
|
45
|
+
|
46
|
+
it "should log them in" do
|
47
|
+
login.should be_successful
|
48
|
+
end
|
49
|
+
end
|
58
50
|
|
59
|
-
|
51
|
+
describe "as an admin" do
|
52
|
+
scenario :admin
|
53
|
+
|
54
|
+
it "should log them in" do
|
55
|
+
login.should be_successful
|
56
|
+
end
|
57
|
+
end
|
60
58
|
end
|
61
59
|
```
|
62
60
|
|
63
|
-
Because scenarios are
|
61
|
+
Because scenarios are simply blocks that are run in the context where they are included, you can use as many as you want:
|
64
62
|
|
65
63
|
```ruby
|
66
|
-
describe "
|
67
|
-
scenario :
|
68
|
-
scenario :
|
64
|
+
describe "GET /message/new when database is down" do
|
65
|
+
scenario :user
|
66
|
+
scenario :database_down
|
69
67
|
|
70
|
-
|
68
|
+
it "should show fail whale" do
|
69
|
+
visit( "/message/new" )
|
70
|
+
response.should contain( "fail whale" )
|
71
|
+
end
|
71
72
|
end
|
72
73
|
```
|
73
74
|
|
74
75
|
And you can nest them:
|
75
76
|
|
76
77
|
```ruby
|
77
|
-
describe "
|
78
|
-
scenario :
|
78
|
+
describe "GET /message/new" do
|
79
|
+
scenario :user
|
79
80
|
|
80
|
-
describe "
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
describe "when database is up" do
|
82
|
+
it "should not show fail whale" do
|
83
|
+
visit( "/message/new" )
|
84
|
+
response.should_not contain( "fail whale" )
|
85
|
+
end
|
84
86
|
end
|
85
87
|
|
86
|
-
describe "
|
87
|
-
scenario :
|
88
|
+
describe "when database is down" do
|
89
|
+
scenario :database_down
|
88
90
|
|
89
|
-
|
91
|
+
it "should show fail whale" do
|
92
|
+
visit( "/message/new" )
|
93
|
+
response.should contain( "fail whale" )
|
94
|
+
end
|
90
95
|
end
|
91
96
|
end
|
92
97
|
```
|
@@ -100,8 +105,7 @@ version. Feel free to open a pull request or just monkey patch the `root()`
|
|
100
105
|
method.
|
101
106
|
|
102
107
|
```ruby
|
103
|
-
Scenario::Fixtures['html/sample.html'] # Returns contents of the fixture as
|
104
|
-
# a string
|
108
|
+
Scenario::Fixtures['html/sample.html'] # Returns contents of the fixture as a string
|
105
109
|
```
|
106
110
|
|
107
111
|
`Scenario::Fixtures` caches the contents of the file so that the file only needs
|
@@ -110,8 +114,10 @@ to be read once.
|
|
110
114
|
Version History
|
111
115
|
===============
|
112
116
|
|
113
|
-
0.
|
114
|
-
|
117
|
+
* 0.3.0 - Remove support for module-based scenarios, allow calling RSpec hooks
|
118
|
+
in scenarios.
|
119
|
+
* 0.2.0 - Add support for RSpec 1.3+
|
120
|
+
* 0.1.0 - Initial release with support for RSpec 2.x
|
115
121
|
|
116
122
|
Contributing to Scenario
|
117
123
|
========================
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/scenario/rspec.rb
CHANGED
@@ -7,9 +7,11 @@ module Scenario
|
|
7
7
|
private
|
8
8
|
|
9
9
|
begin
|
10
|
-
|
10
|
+
# 2.x
|
11
|
+
ExampleGroup = RSpec::Core::ExampleGroup
|
11
12
|
rescue NameError
|
12
|
-
|
13
|
+
# 1.x
|
14
|
+
ExampleGroup = Spec::Example::ExampleGroup
|
13
15
|
end
|
14
16
|
|
15
17
|
module RSpecExtensions
|
@@ -17,34 +19,26 @@ module Scenario
|
|
17
19
|
# ExampleGroup methods
|
18
20
|
module ExampleGroupExtensions
|
19
21
|
|
20
|
-
#
|
22
|
+
# Load a given scenario
|
21
23
|
def scenario( name, &block )
|
22
|
-
|
23
|
-
|
24
|
-
self.
|
24
|
+
@_scenario_context = name.to_sym
|
25
|
+
scenario = Scenario::Scenarios.for( name )
|
26
|
+
self.module_eval( &scenario )
|
25
27
|
end
|
26
28
|
|
27
29
|
end
|
28
|
-
|
30
|
+
ExampleGroup.send :extend, ExampleGroupExtensions
|
29
31
|
|
30
32
|
# Global methods.
|
31
33
|
module ObjectExtensions
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
modul.module_exec( &block ) if block_given?
|
37
|
-
Scenario::Scenarios.register( name, modul )
|
38
|
-
end
|
39
|
-
|
40
|
-
# Syntax sugar for defining a scenario method inside a `describe_scenario`
|
41
|
-
# block.
|
42
|
-
def define( method_name, &block )
|
43
|
-
self.send( :define_method, method_name, &block )
|
35
|
+
def describe_scenario( name, &block )
|
36
|
+
raise "Scenario #{name} has already been defined." if Scenario::Scenarios.for( name )
|
37
|
+
Scenario::Scenarios.add( name, block )
|
44
38
|
end
|
45
39
|
|
46
40
|
end
|
47
|
-
Object.send :include,
|
41
|
+
Object.send :include, ObjectExtensions
|
48
42
|
|
49
43
|
end
|
50
44
|
|
data/lib/scenario/scenario.rb
CHANGED
@@ -4,15 +4,17 @@ module Scenario
|
|
4
4
|
|
5
5
|
class Scenarios
|
6
6
|
|
7
|
+
@@scenarios = {}
|
8
|
+
|
7
9
|
# Add a new scenario.
|
8
|
-
def self.
|
9
|
-
@@scenarios
|
10
|
-
@@scenarios[name.to_sym] = modul
|
10
|
+
def self.add( name, block )
|
11
|
+
@@scenarios[name.to_sym] = block
|
11
12
|
end
|
12
13
|
|
13
|
-
# Get the scenario
|
14
|
+
# Get the scenario block for the given name.
|
14
15
|
def self.for( name )
|
15
|
-
|
16
|
+
name = name.to_sym
|
17
|
+
@@scenarios[name]
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|
data/scenario.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{scenario}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tyson Tate"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-21}
|
13
13
|
s.description = %q{Basic spec scenarios for RSpec. Also includes basic fixtures support.}
|
14
14
|
s.email = %q{tyson@tysontate.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/scenario_spec.rb
CHANGED
@@ -1,52 +1,13 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
require "scenarios/test_scenarios"
|
3
3
|
|
4
|
-
describe "Example with
|
5
|
-
|
6
|
-
lambda { lol }.should raise_error
|
7
|
-
lambda { zomg }.should raise_error
|
8
|
-
lambda { rad_params }.should raise_error
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "Example with block-defined scenario" do
|
13
|
-
scenario :block_defined
|
4
|
+
describe "Example with one scenario" do
|
5
|
+
scenario :simple
|
14
6
|
|
15
|
-
it "should have scenario
|
7
|
+
it "should have a scenario" do
|
8
|
+
@zomg_all.should( be_true )
|
9
|
+
@zomg_each.should( be_true )
|
16
10
|
lol.should == "lol"
|
17
|
-
zomg && @zomg.should( be_true )
|
18
|
-
rad_params( "super" ).should == "This is super rad!"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "Example with block-defined scenario in before hook" do
|
23
|
-
scenario :block_defined
|
24
|
-
|
25
|
-
before :each do
|
26
|
-
lol.should == "lol"
|
27
|
-
zomg && @zomg.should( be_true )
|
28
|
-
rad_params( "super" ).should == "This is super rad!"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should have scenario methods" do
|
32
|
-
@zomg.should be_true
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "Example with module-defined scenario" do
|
37
|
-
scenario :module_defined
|
38
|
-
|
39
|
-
it "should have scenario methods" do
|
40
|
-
lol.should == "for reals"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "Example with mixed-defined scenario" do
|
45
|
-
scenario :mixed_defined
|
46
|
-
|
47
|
-
it "should have scenario methods" do
|
48
|
-
lol.should == "overridden"
|
49
|
-
omg.should == "added"
|
50
11
|
end
|
51
12
|
end
|
52
13
|
|
@@ -54,7 +15,7 @@ describe "Example with multiple scenarios" do
|
|
54
15
|
scenario :scenario_one
|
55
16
|
scenario :scenario_two
|
56
17
|
|
57
|
-
it "should have
|
18
|
+
it "should have both scenarios" do
|
58
19
|
one.should == "present"
|
59
20
|
two.should == "also present"
|
60
21
|
zero_cool?.should be_true
|
@@ -89,3 +50,8 @@ describe "Nested Examples" do
|
|
89
50
|
end
|
90
51
|
end
|
91
52
|
|
53
|
+
describe "Example with no scenario" do
|
54
|
+
it "shouldn't have any scenario methods" do
|
55
|
+
lambda { lol }.should raise_error
|
56
|
+
end
|
57
|
+
end
|
@@ -1,51 +1,33 @@
|
|
1
|
-
describe_scenario :
|
2
|
-
|
3
|
-
|
1
|
+
describe_scenario :simple do
|
2
|
+
before :each do
|
3
|
+
@zomg_each = true
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
@
|
6
|
+
before :all do
|
7
|
+
@zomg_all = true
|
8
8
|
end
|
9
9
|
|
10
|
-
define :rad_params do |how_rad|
|
11
|
-
"This is #{how_rad} rad!"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
module ModuleDefined
|
16
|
-
def lol
|
17
|
-
"for reals"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe_scenario :module_defined, ModuleDefined
|
22
|
-
|
23
|
-
describe_scenario :mixed_defined, ModuleDefined do
|
24
10
|
def lol
|
25
|
-
"
|
26
|
-
end
|
27
|
-
|
28
|
-
def omg
|
29
|
-
"added"
|
11
|
+
"lol"
|
30
12
|
end
|
31
13
|
end
|
32
14
|
|
33
15
|
describe_scenario :scenario_one do
|
34
|
-
|
16
|
+
def one
|
35
17
|
"present"
|
36
18
|
end
|
37
19
|
|
38
|
-
|
20
|
+
def zero_cool?
|
39
21
|
false
|
40
22
|
end
|
41
23
|
end
|
42
24
|
|
43
25
|
describe_scenario :scenario_two do
|
44
|
-
|
26
|
+
def two
|
45
27
|
"also present"
|
46
28
|
end
|
47
29
|
|
48
|
-
|
30
|
+
def zero_cool?
|
49
31
|
true
|
50
32
|
end
|
51
33
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scenario
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tyson Tate
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-21 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|