scenario 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.3.0"
5
+ gem "yard", "~> 0.6.0"
6
+ gem "bundler", "~> 1.0.0"
7
+ gem "jeweler", "~> 1.5.2"
8
+ gem "rcov", ">= 0"
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rcov (0.9.9)
12
+ rspec (2.3.0)
13
+ rspec-core (~> 2.3.0)
14
+ rspec-expectations (~> 2.3.0)
15
+ rspec-mocks (~> 2.3.0)
16
+ rspec-core (2.3.1)
17
+ rspec-expectations (2.3.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.3.0)
20
+ yard (0.6.8)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ jeweler (~> 1.5.2)
28
+ rcov
29
+ rspec (~> 2.3.0)
30
+ yard (~> 0.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tyson Tate
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,117 @@
1
+ Scenario
2
+ ========
3
+
4
+ Scenario brings basic "scenarios" to RSpec. You can define scenarios with a
5
+ block or by passing in a Module (or even both).
6
+
7
+ Block:
8
+
9
+ describe_scenario :admin do |scenario|
10
+ define :setup_user do |name|
11
+ User.create( :name => name, :admin => true )
12
+ end
13
+ end
14
+
15
+ describe "Admin pages" do
16
+ scenario :admin
17
+
18
+ ...
19
+ end
20
+
21
+ Module:
22
+
23
+ module AdminMethods
24
+ def setup_user( name )
25
+ User.create( :name => name, :admin => true )
26
+ end
27
+ end
28
+
29
+ describe_scenario :admin, AdminMethods
30
+
31
+ describe "Admin pages" do
32
+ scenario :admin
33
+
34
+ ...
35
+ end
36
+
37
+ Both:
38
+
39
+ module AdminMethods
40
+ def setup_user( name )
41
+ User.create( :name => name, :admin => true )
42
+ end
43
+ end
44
+
45
+ describe_scenario :admin, AdminMethods do
46
+ define :admin?( user )
47
+ user.admin == true
48
+ end
49
+ end
50
+
51
+ describe "Admin pages" do
52
+ scenario :admin
53
+
54
+ ...
55
+ end
56
+
57
+ Because scenarios are just Modules, you can use as many as you want:
58
+
59
+ describe "Admin pages" do
60
+ scenario :users
61
+ scenario :admin
62
+
63
+ ...
64
+ end
65
+
66
+ And you can nest them:
67
+
68
+ describe "Login" do
69
+ scenario :login
70
+
71
+ describe "as an admin" do
72
+ scenario :admin
73
+
74
+ ...
75
+ end
76
+
77
+ describe "as a regular user" do
78
+ scenario :user
79
+
80
+ ...
81
+ end
82
+ end
83
+
84
+ Fixtures
85
+ --------
86
+
87
+ Basic fixture support is also included. (Please note that fixtures are currently
88
+ hard-coded to `spec/scenarios/fixtures`. It will be configurable in a future
89
+ version. Feel free to open a pull request or just monkey patch the `root()`
90
+ method.
91
+
92
+ Scenario::Fixtures['html/sample.html'] # Returns contents of the
93
+ # fixture as a string
94
+
95
+ `Scenario::Fixtures` caches the contents of the file so that the file only needs
96
+ to be read once.
97
+
98
+ Contributing to Scenario
99
+ ========================
100
+
101
+ * Check out the latest master to make sure the feature hasn't been implemented
102
+ or the bug hasn't been fixed yet
103
+ * Check out the issue tracker to make sure someone already hasn't requested it
104
+ and/or contributed it
105
+ * Fork the project
106
+ * Start a feature/bugfix branch
107
+ * Commit and push until you are happy with your contribution
108
+ * Make sure to add tests for it. This is important so I don't break it in a
109
+ future version unintentionally.
110
+ * Please try not to mess with the Rakefile, version, or history. If you want to
111
+ have your own version, or is otherwise necessary, that is fine, but please
112
+ isolate to its own commit so I can cherry-pick around it.
113
+
114
+ Copyright
115
+ =========
116
+
117
+ Copyright (c) 2011 Tyson Tate. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "scenario"
16
+ gem.homepage = "http://github.com/tysontate/scenario"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Basic spec scenarios for RSpec.}
19
+ gem.description = %Q{Basic spec scenarios for RSpec. Also includes basic fixtures support.}
20
+ gem.email = "tyson@tysontate.com"
21
+ gem.authors = ["Tyson Tate"]
22
+ gem.add_development_dependency "rspec", "~> 2.3.0"
23
+ gem.add_development_dependency "yard", "~> 0.6.0"
24
+ gem.add_development_dependency "bundler", "~> 1.0.0"
25
+ gem.add_development_dependency "jeweler", "~> 1.5.2"
26
+ gem.add_development_dependency "rcov", ">= 0"
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'yard'
44
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/scenario.rb ADDED
@@ -0,0 +1,5 @@
1
+ $: << File.expand_path( File.dirname( __FILE__ ) )
2
+
3
+ require 'scenario/fixtures'
4
+ require 'scenario/scenario'
5
+ require 'scenario/rspec'
@@ -0,0 +1,27 @@
1
+ module Scenario
2
+
3
+ # Easy access to fixture files (HTML, CSS, JSON, etc.)
4
+ class Fixtures
5
+
6
+ def self.[]( rel_path )
7
+ @content_cache ||= {}
8
+
9
+ unless @content_cache.key?( rel_path )
10
+ path = "#{self.root}/#{rel_path}"
11
+ raise "#{path} doesn't exist or is not a file." unless File.file?( path )
12
+ @content_cache[rel_path] = File.open( path, 'r' ).read
13
+ end
14
+
15
+ @content_cache[rel_path]
16
+ end
17
+
18
+ protected
19
+
20
+ def self.root
21
+ # TODO: Use spec root (?)
22
+ "#{Dir.pwd}/spec/scenarios/fixtures"
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,45 @@
1
+ # ===================
2
+ # = RSpec additions =
3
+ # ===================
4
+
5
+ module Scenario
6
+
7
+ private
8
+
9
+ module RSpecExtensions
10
+
11
+ # ExampleGroup methods
12
+ module ExampleGroupExtensions
13
+
14
+ # Tell Scenario which scenario you want to use
15
+ def scenario( name, &block )
16
+ modul = Scenario::Scenarios.for( name )
17
+ modul.module_exec( &block ) if block_given?
18
+ self.send( :include, modul )
19
+ end
20
+
21
+ end
22
+ RSpec::Core::ExampleGroup.send :extend, Scenario::RSpecExtensions::ExampleGroupExtensions
23
+
24
+ # Global methods.
25
+ module ObjectExtensions
26
+
27
+ # Set up a new scenario and add to the collection of scenarios.
28
+ def describe_scenario( name, base=nil, &block )
29
+ modul = base ? base.dup : Module.new
30
+ modul.module_exec( &block ) if block_given?
31
+ Scenario::Scenarios.register( name, modul )
32
+ end
33
+
34
+ # Syntax sugar for defining a scenario method inside a `describe_scenario`
35
+ # block.
36
+ def define( method_name, &block )
37
+ self.send( :define_method, method_name, &block )
38
+ end
39
+
40
+ end
41
+ Object.send :include, Scenario::RSpecExtensions::ObjectExtensions
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,20 @@
1
+ module Scenario
2
+
3
+ private
4
+
5
+ class Scenarios
6
+
7
+ # Add a new scenario.
8
+ def self.register( name, modul )
9
+ @@scenarios ||= {}
10
+ @@scenarios[name.to_sym] = modul
11
+ end
12
+
13
+ # Get the scenario module for the given name.
14
+ def self.for( name )
15
+ @@scenarios[name.to_sym] || ( raise "No scenario named #{name.inspect}." )
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Scenario::Fixtures do
4
+ it "provides text" do
5
+ Scenario::Fixtures["basic.text"].should =~ /squeeze/
6
+ end
7
+ end
@@ -0,0 +1,91 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require "scenarios/test_scenarios"
3
+
4
+ describe "Example with no scenario" do
5
+ it "shouldn't have any scenario methods" do
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
14
+
15
+ it "should have scenario methods" do
16
+ 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
+ end
51
+ end
52
+
53
+ describe "Example with multiple scenarios" do
54
+ scenario :scenario_one
55
+ scenario :scenario_two
56
+
57
+ it "should have scenario methods" do
58
+ one.should == "present"
59
+ two.should == "also present"
60
+ zero_cool?.should be_true
61
+ end
62
+ end
63
+
64
+ describe "Nested Examples" do
65
+ scenario :scenario_one
66
+
67
+ it "has scenario methods, but not those of descendant examples" do
68
+ one.should == "present"
69
+ lambda { two }.should raise_error
70
+ zero_cool?.should be_false
71
+ end
72
+
73
+ describe "(one deeper)" do
74
+ scenario :scenario_two
75
+
76
+ it "has scenario (local and parent example) methods" do
77
+ one.should == "present"
78
+ two.should == "also present"
79
+ zero_cool?.should be_true
80
+ end
81
+ end
82
+
83
+ describe "(one deeper, without extra scenario)" do
84
+ it "has parent scenario methods" do
85
+ one.should == "present"
86
+ lambda { two }.should raise_error
87
+ zero_cool?.should be_false
88
+ end
89
+ end
90
+ end
91
+
@@ -0,0 +1,4 @@
1
+ There comes a time in every man's life
2
+ When he's got to handle shit up on his own
3
+ Can't depend on friends to help you in a squeeze
4
+ Believe me they got problems of they own
@@ -0,0 +1,51 @@
1
+ describe_scenario :block_defined do
2
+ define :lol do
3
+ "lol"
4
+ end
5
+
6
+ define :zomg do
7
+ @zomg = true
8
+ end
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
+ def lol
25
+ "overridden"
26
+ end
27
+
28
+ def omg
29
+ "added"
30
+ end
31
+ end
32
+
33
+ describe_scenario :scenario_one do
34
+ define :one do
35
+ "present"
36
+ end
37
+
38
+ define "zero_cool?" do
39
+ false
40
+ end
41
+ end
42
+
43
+ describe_scenario :scenario_two do
44
+ define :two do
45
+ "also present"
46
+ end
47
+
48
+ define "zero_cool?" do
49
+ true
50
+ end
51
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift( File.join( File.dirname( __FILE__ ), '..', 'lib' ) )
2
+
3
+ require 'rspec'
4
+ require 'scenario'
metadata ADDED
@@ -0,0 +1,242 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scenario
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Tyson Tate
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-20 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: rspec
24
+ type: :development
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 2
33
+ - 3
34
+ - 0
35
+ version: 2.3.0
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ name: yard
40
+ type: :development
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 7
47
+ segments:
48
+ - 0
49
+ - 6
50
+ - 0
51
+ version: 0.6.0
52
+ requirement: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ prerelease: false
55
+ name: bundler
56
+ type: :development
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ hash: 23
63
+ segments:
64
+ - 1
65
+ - 0
66
+ - 0
67
+ version: 1.0.0
68
+ requirement: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ prerelease: false
71
+ name: jeweler
72
+ type: :development
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ hash: 7
79
+ segments:
80
+ - 1
81
+ - 5
82
+ - 2
83
+ version: 1.5.2
84
+ requirement: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ prerelease: false
87
+ name: rcov
88
+ type: :development
89
+ version_requirements: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirement: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ prerelease: false
101
+ name: rspec
102
+ type: :development
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 2
111
+ - 3
112
+ - 0
113
+ version: 2.3.0
114
+ requirement: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ prerelease: false
117
+ name: yard
118
+ type: :development
119
+ version_requirements: &id007 !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ hash: 7
125
+ segments:
126
+ - 0
127
+ - 6
128
+ - 0
129
+ version: 0.6.0
130
+ requirement: *id007
131
+ - !ruby/object:Gem::Dependency
132
+ prerelease: false
133
+ name: bundler
134
+ type: :development
135
+ version_requirements: &id008 !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ~>
139
+ - !ruby/object:Gem::Version
140
+ hash: 23
141
+ segments:
142
+ - 1
143
+ - 0
144
+ - 0
145
+ version: 1.0.0
146
+ requirement: *id008
147
+ - !ruby/object:Gem::Dependency
148
+ prerelease: false
149
+ name: jeweler
150
+ type: :development
151
+ version_requirements: &id009 !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ~>
155
+ - !ruby/object:Gem::Version
156
+ hash: 7
157
+ segments:
158
+ - 1
159
+ - 5
160
+ - 2
161
+ version: 1.5.2
162
+ requirement: *id009
163
+ - !ruby/object:Gem::Dependency
164
+ prerelease: false
165
+ name: rcov
166
+ type: :development
167
+ version_requirements: &id010 !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ requirement: *id010
177
+ description: Basic spec scenarios for RSpec. Also includes basic fixtures support.
178
+ email: tyson@tysontate.com
179
+ executables: []
180
+
181
+ extensions: []
182
+
183
+ extra_rdoc_files:
184
+ - LICENSE.txt
185
+ - README.markdown
186
+ files:
187
+ - .document
188
+ - .rspec
189
+ - Gemfile
190
+ - Gemfile.lock
191
+ - LICENSE.txt
192
+ - README.markdown
193
+ - Rakefile
194
+ - VERSION
195
+ - lib/scenario.rb
196
+ - lib/scenario/fixtures.rb
197
+ - lib/scenario/rspec.rb
198
+ - lib/scenario/scenario.rb
199
+ - spec/fixtures_spec.rb
200
+ - spec/scenario_spec.rb
201
+ - spec/scenarios/fixtures/basic.text
202
+ - spec/scenarios/test_scenarios.rb
203
+ - spec/spec_helper.rb
204
+ has_rdoc: true
205
+ homepage: http://github.com/tysontate/scenario
206
+ licenses:
207
+ - MIT
208
+ post_install_message:
209
+ rdoc_options: []
210
+
211
+ require_paths:
212
+ - lib
213
+ required_ruby_version: !ruby/object:Gem::Requirement
214
+ none: false
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ hash: 3
219
+ segments:
220
+ - 0
221
+ version: "0"
222
+ required_rubygems_version: !ruby/object:Gem::Requirement
223
+ none: false
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ hash: 3
228
+ segments:
229
+ - 0
230
+ version: "0"
231
+ requirements: []
232
+
233
+ rubyforge_project:
234
+ rubygems_version: 1.4.2
235
+ signing_key:
236
+ specification_version: 3
237
+ summary: Basic spec scenarios for RSpec.
238
+ test_files:
239
+ - spec/fixtures_spec.rb
240
+ - spec/scenario_spec.rb
241
+ - spec/scenarios/test_scenarios.rb
242
+ - spec/spec_helper.rb