eol_scenarios 0.3.3

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
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,51 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
43
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
44
+
45
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
46
+
47
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
48
+
49
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
50
+
51
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
data/README.rdoc ADDED
@@ -0,0 +1,58 @@
1
+ = scenarios
2
+
3
+ The idea behind 'scenarios' is simple. Scenarions are basically just organized bits of arbitrary ruby code.
4
+
5
+ == why?
6
+
7
+ Here's why scenarios were originally written ... you may use them however you wish!
8
+
9
+ I had a Rails application and I wanted to be able to do something like this:
10
+
11
+ $ rake scenarios:load SCENARIO=one_thousand_users
12
+
13
+ ... which would put 1,000 users in the database.
14
+
15
+ Sometimes, while testing out my application's functionality in a browser, I would
16
+ want to setup some scenario to test. Maybe I'm working on X feature and it would
17
+ be helpful if I had Y data in the database to work with. Typically, I would
18
+ open up `script/console` and create abunchof Y data manually. But ... wouldn't it
19
+ be useful if we could automate that?
20
+
21
+ Also, our application requires *some* data to be in the database for the app to
22
+ load properly. So we created a scenario that loads up the minimum amount of
23
+ data required to run the app!
24
+
25
+ == documentation
26
+
27
+ Read the RDoc[http://openrain.github.com/scenarios]
28
+
29
+ == how?
30
+
31
+ $ sudo gem install remi-scenarios -s http://gems.github.com
32
+
33
+ then, if you're in a Rails project ...
34
+
35
+ $ ./script/generate scenario Foo
36
+
37
+ to see all defined scenarios ...
38
+
39
+ $ rake scenarios
40
+
41
+ to load a particular scenario ...
42
+
43
+ $ rake scenarios:load NAME=my_scenario
44
+ $ rake scenarios:load NAME=my_scenario,and_some_more_scenarios
45
+
46
+ == what else?
47
+
48
+ more documentation to come soon!
49
+
50
+ == TODO
51
+
52
+ - add a 'scenario' bin script so you don't necessarily have to use rake? potentially? maybe check for local .scenariorc?
53
+ - should be able to 'show' a full, long description of what a scenario does (*full* header comment)
54
+ - document the context that scenarios are loaded within ... right now we're using #load, which is nice because it gets line numbers for exceptions ... altho eval'ing the code gives us more control over the context its loaded in
55
+ - add dependencies so one scenario can call another one
56
+ - make the scenario directory for the generator configurable (and that dir should always be included in the Scenario loadpath
57
+ - make all scenarios load within a specific context and add hooks so people can update/modify that context
58
+ - write a spec to make sure that the load paths work properly and multiple directories can have scenarios with the same name ... the directories added last should override the previous ones. also make sure paths are uniq ... if i add 'foo' and 'foo' is already there, it should make foo the last path (move it to the end)
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "eol_scenarios"
8
+ gem.summary = %Q{Execute arbitrary blocks of ruby code for loading testing scenarios}
9
+ gem.description = %Q{Based on openrain-scenarios, q.v. Depends on hard-to-find gems at the moment: remi-indifferent-variable-hash and remi-simplecli}
10
+ gem.email = "jrice.blue@gmail.com"
11
+ gem.homepage = "http://github.com/JRice/eol_scenarios"
12
+ gem.authors = ["Jeremy Rice"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem.add_dependency 'remi-indifferent-variable-hash'
15
+ # gem.add_dependency 'remi-simplecli'
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "eol_scenarios #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.3
@@ -0,0 +1 @@
1
+ $set_by_load_me = 'I was set by load_me'
@@ -0,0 +1 @@
1
+ $set_by_load_me_too = 'I was set by load_me_too!'
@@ -0,0 +1,2 @@
1
+ # foo!
2
+ $set_by_foo = 'hello from foo!'
@@ -0,0 +1,9 @@
1
+ # i am the summary
2
+ #
3
+ # only the first line
4
+ # should be included in the summary
5
+ #
6
+ #no space here
7
+ #
8
+ $set_by_first_scenario = 'hello from first scenario!'
9
+ # i'm a comment after some code, i am NOT part of the header
@@ -0,0 +1,10 @@
1
+ # loads more stuff
2
+ #
3
+ # does this
4
+ # and that
5
+ #
6
+ # ---
7
+ # dependencies: [ :load_stuff ]
8
+ #
9
+ $times_loads_more_stuff_has_been_run ||= 0
10
+ $times_loads_more_stuff_has_been_run += 1
@@ -0,0 +1,3 @@
1
+ # loads stuff
2
+ $times_loads_stuff_has_been_run ||= 0
3
+ $times_loads_stuff_has_been_run += 1
@@ -0,0 +1,10 @@
1
+ # i have some yaml
2
+ #
3
+ # hi there
4
+ # indeed i do
5
+ #
6
+ # ---
7
+ # foo: x
8
+ # bar: that
9
+ #
10
+ puts "i am the source code"
@@ -0,0 +1,222 @@
1
+ # a Scenario is some set of data/logic that can be loaded up easily
2
+ # to run an application against.
3
+ #
4
+ # if you need to enter abunchof data manually into the a website
5
+ # to test something you're working on, this is a good candidate for
6
+ # a scenario.
7
+ #
8
+ # we can also use scenarios for loading up the base foundation of
9
+ # data that's required to load the web application
10
+ #
11
+ # TODO define what is public/private and document public API in README and
12
+ # actually give private methods a private visibility
13
+ #
14
+ class EolScenario
15
+ include IndifferentVariableHash
16
+
17
+ attr_accessor :file_path
18
+
19
+ def initialize file_path
20
+ @file_path = file_path
21
+ source_code # does some parsing ... eager load this! otherwise Scenario[:first].some_var won't work
22
+ end
23
+
24
+ def name
25
+ File.basename(file_path).sub(/\.rb$/, '')
26
+ end
27
+ alias to_s name
28
+
29
+ # returns a formatted string, showing information
30
+ # about this current scenario
31
+ def info
32
+ str = <<INFO
33
+ Scenario: #{ name }
34
+ Summary: #{ summary }
35
+ Description: #{ description_without_summary }
36
+ INFO
37
+ variables.each do |key, value|
38
+ str << "#{ key }: #{ value.inspect }\n"
39
+ end
40
+ str
41
+ end
42
+
43
+ # if the first line of the scenario's source code
44
+ # is a comment, we use it as the scenario's summary
45
+ #
46
+ # ideally, all scenarios should have a short simple summary
47
+ #
48
+ def summary
49
+ if first_line =~ /^#/
50
+ first_line.sub(/^#*/, '').strip
51
+ else
52
+ ''
53
+ end
54
+ end
55
+
56
+ def first_line
57
+ header.split("\n").first #.gsub(/^#* ?/, '')
58
+ end
59
+
60
+ def source_code
61
+ unless @source_code
62
+ # the first time we read in the source code,
63
+ # see if there are any variables in the header
64
+ # and, if so, set them via IndifferentVariableHash
65
+ @source_code = File.read file_path
66
+ yaml_frontmatter = header.gsub(/^#* ?/, '')[/^---.*/m]
67
+ if yaml_frontmatter
68
+ require 'yaml'
69
+ header_variables = YAML::load(yaml_frontmatter)
70
+ variables.merge!(header_variables) if header_variables
71
+ end
72
+ end
73
+ @source_code
74
+ end
75
+
76
+ def description
77
+ header.gsub(/^#* ?/, '').gsub(/^---.*/m, '').strip # gets rid of comment hashes and yaml
78
+ end
79
+
80
+ def description_without_summary
81
+ parts = description.split("\n")
82
+ parts.shift
83
+ parts.join("\n")
84
+ end
85
+
86
+ # evaluates the code of the scenario
87
+ def load
88
+ self.class.load self # pass the loading off to the class
89
+ end
90
+
91
+ # Comment header, any comments at the top of the source code
92
+ def header
93
+ source_code.gsub /\n^[^#].*/m, ''
94
+ end
95
+
96
+ class << self
97
+
98
+ # an array of the paths where scenarios can be found
99
+ #
100
+ # any .rb file found in these directories is assumed to
101
+ # be a scenario
102
+ #
103
+ attr_accessor :load_paths, :verbose, :before_blocks
104
+
105
+ # returns all Scenarios found using Scenario#load_paths
106
+ def all
107
+ load_paths.inject([]) do |all_scenarios, load_path|
108
+ Dir[ File.join(load_path, '**', '*.rb') ].each do |found_scenario_file|
109
+ all_scenarios << EolScenario.new(found_scenario_file)
110
+ end
111
+ all_scenarios
112
+ end
113
+ end
114
+
115
+ def verbose= value
116
+ if value == true && @verbose != true
117
+ puts "Scenario verbose enable."
118
+ puts "Scenario load_paths => #{ EolScenario.load_paths.inspect }"
119
+ puts "#{ EolScenario.all.length } scenario(s) found"
120
+ end
121
+ @verbose = value
122
+ end
123
+
124
+ # run some block of code before any scenarios run
125
+ #
126
+ # good for last-minute require statements and whatnot
127
+ #
128
+ def before &block
129
+ @before_blocks ||= []
130
+ @before_blocks << block if block
131
+ end
132
+
133
+ # returns a scenario by name, eg. Scenario[:foo]
134
+ #
135
+ # if 1 name is passed in, we'll return that scenario or nil
136
+ #
137
+ # if more than 1 name is passed in, we'll return an array of
138
+ # scenarios (or an empty array)
139
+ #
140
+ def [] *names
141
+ # puts "Scenario#{ names.inspect }" if Scenario.verbose
142
+ if names.length == 1
143
+ all.find {|scenario| scenario.name.downcase == names.first.to_s.downcase }
144
+ else
145
+ names.map {|name| self[ name ] }.compact
146
+ end
147
+ end
148
+
149
+ # loads a Scenario, evaluating its code
150
+ #
151
+ # we do this here so we can easily eval in a certain context,
152
+ # if we want to add a context later
153
+ #
154
+ # Scenario.load @scenario1, @scenario2
155
+ # Scenario.load :names, 'work', :too
156
+ #
157
+ def load *scenarios
158
+ puts "EolScenario.load(#{ scenarios.map {|s| s.to_s }.join(', ') })" if EolScenario.verbose
159
+ @before_blocks.each { |b| b.call } if @before_blocks and not @before_blocks.empty?
160
+
161
+ # TODO should be able to define some block that scenarios get evaluated in!
162
+ # or some things that scenarios might want to require or ...
163
+
164
+ options = ( scenarios.last.is_a?(Hash) ) ? scenarios.pop : { }
165
+ options[:unique] ||= true # whether each scenario passed has to be unique ... will likely change this to be true by default
166
+ options[:whiny] = true if options[:whiny].nil?
167
+
168
+ # make sure everything is actually a Scenario object
169
+ #
170
+ # after this, we can safely assume that everything is a scenario!
171
+ #
172
+ scenarios.map! do |scenario|
173
+ scenario.is_a?(EolScenario) ? scenario : self[scenario]
174
+ end
175
+ scenarios.compact!
176
+
177
+ scenarios = scenarios.inject([]) do |all, scenario|
178
+ all += EolScenario[ nil, *scenario.dependencies ] if scenario.dependencies
179
+ all << scenario
180
+ all
181
+ end
182
+ scenarios.compact!
183
+
184
+ puts "[ after dependencies, scenarios => #{ scenarios.map {|s| s.to_s }.join(', ') } ]" if EolScenario.verbose
185
+
186
+ scenarios = scenarios.inject([]) do |all, scenario|
187
+ existing_scenario = all.find {|s| s.name == scenario.name }
188
+ if existing_scenario
189
+ # the last scenario with the given name "wins" (but we need to persist order)
190
+ index_of_existing_scenario = all.index existing_scenario
191
+ all.delete_at index_of_existing_scenario
192
+ all.insert index_of_existing_scenario, scenario
193
+ else
194
+ all << scenario
195
+ end
196
+ all
197
+ end if options[:unique]
198
+
199
+ puts "scenarios to load: #{ scenarios.map {|s| s.to_s }.join(', ') }" if EolScenario.verbose
200
+ scenarios.each do |scenario|
201
+ scenario = self[scenario] unless scenario.is_a?EolScenario # try getting using self[] if not a scenario
202
+ puts "... loading #{ scenario.name } (#{ scenario.summary })" if EolScenario.verbose
203
+ begin
204
+ if scenario.is_a? EolScenario
205
+ puts "loading scenario: #{ scenario.file_path }" if EolScenario.verbose
206
+
207
+ # TODO update to eval ... should load in a custom context ...
208
+ # the eval should also catch exceptions and print the
209
+ # line number that threw the exception, etc etc
210
+ Kernel::load scenario.file_path
211
+ else
212
+ puts "Unsure how to load scenario: #{ scenario.inspect }" if options[:whiny]
213
+ end
214
+ rescue => ex
215
+ puts "An Exception was thrown by scenario: #{ scenario.name }" if options[:whiny]
216
+ raise ex
217
+ end
218
+ end
219
+ end
220
+ end
221
+
222
+ end
@@ -0,0 +1,34 @@
1
+ # Top-level namespace for EolScenarios
2
+ #
3
+ # Holds configuration for EolScenarios
4
+ # and acts as a bit of a utility class,
5
+ # holding lots of methods / logic
6
+ # used by EolScenarios.
7
+ #
8
+ class EolScenarios
9
+ class << self
10
+
11
+ # include IndifferentVariableHash in EolScenarios so we can
12
+ # get/set easily configuration settings for EolScenarios
13
+ include IndifferentVariableHash
14
+
15
+ # alias config to variables attribute provided by
16
+ # IndifferentVariableHash so we can say:
17
+ #
18
+ # # these all return the value of configuration
19
+ # # setting 'foo'
20
+ # EolScenarios.config.foo
21
+ # EolScenarios.config[:foo]
22
+ # EolScenarios[:foo]
23
+ # EolScenarios.foo
24
+ #
25
+ alias config variables
26
+
27
+ # returns a formatted string displaying
28
+ # information about the current EolScenarios
29
+ # environment and conifuguration, etc etc.
30
+ def info
31
+ "hello from EolScenarios#info"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ class EolScenario
2
+
3
+ # scenario helpers that can be used in your specs
4
+ #
5
+ # specifically, a #scenarios method for easily loading scenarios
6
+ #
7
+ module Spec
8
+
9
+ # scenarios to load in a spec
10
+ #
11
+ # scenario :foo
12
+ # scenarios :foo, :bar
13
+ # scenarios :foo, :bar, :before => :all
14
+ # scenarios :foo, :bar, :before => :each
15
+ #
16
+ # defaults to before each
17
+ #
18
+ # to use this in your own specs, in your spec_helper.rb
19
+ #
20
+ # require 'eol_scenarios'
21
+ #
22
+ # Spec::Runner.configure do |config|
23
+ # include EolScenario::Spec
24
+ # end
25
+ #
26
+ # is RSpec is loaded, we'll load up the EolScenario::Spec for
27
+ # you automatically. if you need to manually load this:
28
+ #
29
+ # require 'eol_scenarios/spec'
30
+ #
31
+ def scenario *scenarios
32
+ puts "EolScenario::Spec::Helper.scenario #{ scenarios.inspect }" if EolScenario.verbose
33
+ options = (scenarios.last.is_a?Hash) ? scenarios.pop : { }
34
+ options[:before] ||= :each
35
+ before options[:before] do
36
+ EolScenario.load *scenarios
37
+ end
38
+ end
39
+ alias scenarios scenario
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,80 @@
1
+ # here be rake tasks for scenarios
2
+ #
3
+ # you can get them in your Rakefile by:
4
+ # require 'eol_scenarios/tasks'
5
+ # EolScenario.load_paths = [ 'path/to/my/scenarios/**/*' ]
6
+
7
+ require 'eol_scenarios'
8
+
9
+ desc 'Print all available scenarios'
10
+ task :scenarios do
11
+ if EolScenario.all.empty?
12
+ puts "there are no scenarios. add some to one of the EolScenario.load_paths: #{ EolScenario.load_paths.inspect }"
13
+ else
14
+ EolScenario.all.each do |scenario|
15
+ puts "#{ scenario.name }: #{ scenario.summary }"
16
+ end
17
+ end
18
+ end
19
+
20
+ namespace :scenarios do
21
+
22
+ desc 'scenarios:load NAME=foo OR NAME=a,b,c'
23
+ task :load => ( (defined?RAILS_ENV) ? :environment : nil ) do
24
+ puts "called scenarios:load" if EolScenario.verbose
25
+ if ENV['NAME']
26
+ names = ENV['NAME'].split(',')
27
+ EolScenario.load *names
28
+ else
29
+ puts "you need to pass NAME=scenario_name to load a scenario"
30
+ end
31
+ end
32
+
33
+ desc 'scenarios:show NAME=foo OR NAME=a,b,c'
34
+ task :show do
35
+ if ENV['NAME']
36
+ names = ENV['NAME'].split(',')
37
+ names.each do |scenario_name|
38
+ if scenario = EolScenario[scenario_name]
39
+ puts scenario.info
40
+ puts ('-' * 40)
41
+ else
42
+ puts "Scenario not found: #{ scenario_name }"
43
+ end
44
+ end
45
+ else
46
+ puts "you need to pass NAME=scenario_name to load a scenario"
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ =begin
53
+ if defined?RAILS_ENV
54
+ # rails-specific task
55
+
56
+ desc 'this will clear the database, load scenarios, & run the site'
57
+ task :run => :environment do
58
+ if RAILS_ENV == 'test'
59
+ if ENV['NAME']
60
+
61
+ puts "clearing database ..."
62
+ Rake::Task[:truncate].invoke # this isn't defined in scenarios! need to not call this or include a :truncate task
63
+
64
+ puts "loading scenarios ..."
65
+ names = ENV['NAME'].split(',')
66
+ EolScenario.load *names
67
+
68
+ puts "running the site ..."
69
+ require 'commands/server'
70
+
71
+ else
72
+ puts "Usage: rake:run NAME=the_names,of_some,scenarios_to_load RAILS_ENV=test"
73
+ end
74
+ else
75
+ puts "sorry, i'm not comfortable doing this in any environment but 'test'"
76
+ end
77
+ end
78
+
79
+ end
80
+ =end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'indifferent-variable-hash'
5
+ require 'eol_scenarios/eol_scenarios'
6
+ require 'eol_scenarios/eol_scenario'
7
+
8
+ # TODO not 100% sure if i want this
9
+ EolScenario.load_paths ||= [ 'scenarios' ] # default to a 'scenarios' directory relative to your current location
10
+
11
+ # TODO get rid of this ... switch to a real logger
12
+ EolScenario.verbose = false
13
+
14
+ # TODO get rid of this, i think i want to *explicitly* require this
15
+ require 'eol_scenarios/spec' if defined? Spec
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Creates a new scenario
3
+
4
+ Examples:
5
+ `./script/generate scenario Foo`
@@ -0,0 +1,44 @@
1
+ # This generator creates a new 'scenario'
2
+ class ScenarioGenerator < Rails::Generator::Base
3
+
4
+ attr_accessor :name_of_scenario_to_create, :name_of_scenario_file_to_create
5
+
6
+ # `./script/generate scenario foo` will result in:
7
+ #
8
+ # runtime_args: ['foo']
9
+ # runtime_options: {:quiet=>false, :generator=>"scenario", :command=>:create, :collision=>:ask}
10
+ #
11
+ def initialize(runtime_args, runtime_options = {})
12
+ setup_rails_to_run_scenarios
13
+ @name_of_scenario_to_create = runtime_args.join(' ')
14
+ @name_of_scenario_file_to_create = runtime_args.join('_').downcase
15
+ super
16
+ end
17
+
18
+ # this should be done by ./script/generate blackbox
19
+ def setup_rails_to_run_scenarios
20
+ rakefile = File.join RAILS_ROOT, 'Rakefile'
21
+ if File.file? rakefile
22
+ source = File.read rakefile
23
+ unless source =~ /require .scenarios.tasks./
24
+ File.open( rakefile, 'a' ) do |f|
25
+ f << %[require 'scenarios/tasks']
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def manifest
32
+ record do |m|
33
+ m.directory 'scenarios'
34
+ m.template 'scenario.erb', "scenarios/#{ name_of_scenario_file_to_create }.rb"
35
+ end
36
+ end
37
+
38
+ protected
39
+
40
+ def banner
41
+ "Usage: #{$0} _scenario Name of Scenario to Create"
42
+ end
43
+
44
+ end
@@ -0,0 +1,5 @@
1
+ # my one-line description of the <%= name_of_scenario_to_create %> scenario
2
+
3
+ $foo = "the <%= name_of_scenario_file_to_create %> scenario sets a global variable!"
4
+
5
+ puts "Hello from the <%= name_of_scenario_to_create %> scenario!"
@@ -0,0 +1,167 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe EolScenario do
4
+
5
+ def path_to_test_scenarios
6
+ File.join File.dirname(__FILE__), '..', 'examples', 'scenarios'
7
+ end
8
+ def path_to_more_scenarios
9
+ File.join File.dirname(__FILE__), '..', 'examples', 'more_scenarios'
10
+ end
11
+
12
+ before do
13
+ EolScenario.load_paths = [ path_to_test_scenarios ]
14
+ $set_by_first_scenario = nil
15
+ $set_by_foo = nil
16
+ end
17
+
18
+ before :all do
19
+ @original_scenario_paths = EolScenario.load_paths
20
+ end
21
+ after :all do
22
+ EolScenario.load_paths = @original_scenario_paths
23
+ end
24
+
25
+ # PENDING
26
+ # it 'should grab variables from header (yaml?)'
27
+ # it 'should not *require* a summary'
28
+ # it 'should not *require* a description'
29
+
30
+ it 'should find scenario files properly' do
31
+ EolScenario.load_paths = []
32
+ EolScenario.all.should be_empty
33
+
34
+ EolScenario.load_paths = [ path_to_test_scenarios ]
35
+ EolScenario.all.length.should == 1
36
+ EolScenario.all.first.name.should == 'first'
37
+
38
+ EolScenario.load_paths << path_to_more_scenarios
39
+ EolScenario.all.length.should == 2
40
+ EolScenario.all.map(&:name).should include('first')
41
+ EolScenario.all.map(&:name).should include('foo')
42
+ end
43
+
44
+ it 'should be easy to get a scenario by name' do
45
+ EolScenario[:first].name.should == 'first'
46
+ EolScenario['first'].name.should == 'first'
47
+
48
+ EolScenario[:foo].should be_nil
49
+ EolScenario.load_paths << path_to_more_scenarios
50
+ EolScenario[:foo].should_not be_nil
51
+ end
52
+
53
+ it 'should be easy to get multiple scenarios by name' do
54
+ EolScenario[:first, :nonexistent, :notfound].length.should == 1
55
+ EolScenario[:first, :nonexistent, :notfound].first.name.should == 'first'
56
+
57
+ EolScenario[:first, :nonexistent, :foo].length.should == 1
58
+ EolScenario.load_paths << path_to_more_scenarios
59
+ EolScenario[:first, :nonexistent, :foo].length.should == 2
60
+ EolScenario[:first, :nonexistent, :foo].map(&:name).should include('first')
61
+ EolScenario[:first, :nonexistent, :foo].map(&:name).should include('foo')
62
+ end
63
+
64
+ it 'should have a name' do
65
+ EolScenario.all.first.should be_a_kind_of(EolScenario)
66
+ EolScenario.all.first.name.should == 'first'
67
+ end
68
+
69
+ it 'should have a summary' do
70
+ EolScenario.all.first.summary.should == 'i am the summary'
71
+ end
72
+
73
+ it 'should have a description' do
74
+ EolScenario.all.first.description.should == "i am the summary\n\n only the first line\n should be included in the summary\n\nno space here"
75
+ end
76
+
77
+ it 'should allow yaml in the header to load up some custom variables (needs to be a hash)' do
78
+ path = File.join File.dirname(__FILE__), '..', 'examples', 'yaml_frontmatter'
79
+ EolScenario.load_paths << path
80
+
81
+ EolScenario[:yaml_in_header].name.should == 'yaml_in_header'
82
+ EolScenario[:yaml_in_header].summary.should == 'i have some yaml'
83
+ EolScenario[:yaml_in_header].description.should == "i have some yaml\n\n hi there\n indeed i do"
84
+ EolScenario[:yaml_in_header].header.should include('foo: x')
85
+ EolScenario[:yaml_in_header].foo.should == 'x'
86
+ end
87
+
88
+ it 'should be loadable' do
89
+ $set_by_first_scenario.should be_nil
90
+ EolScenario[:first].load
91
+ $set_by_first_scenario.should == 'hello from first scenario!'
92
+ end
93
+
94
+ it 'should be able to load multiple scenarios and run any dependencies' do
95
+ $times_loads_stuff_has_been_run, $times_loads_more_stuff_has_been_run = nil, nil
96
+ path = File.join File.dirname(__FILE__), '..', 'examples', 'testing_dependencies'
97
+ EolScenario.load_paths << path
98
+
99
+ EolScenario[:load_more_stuff].dependencies.should include(:load_stuff)
100
+
101
+ $times_loads_stuff_has_been_run.should be_nil
102
+ $times_loads_more_stuff_has_been_run.should be_nil
103
+
104
+ EolScenario.load :load_stuff, :unique => false
105
+ $times_loads_stuff_has_been_run.should == 1
106
+ $times_loads_more_stuff_has_been_run.should be_nil
107
+
108
+ EolScenario.load :load_stuff, :load_stuff, :unique => false
109
+ $times_loads_stuff_has_been_run.should == 3
110
+ $times_loads_more_stuff_has_been_run.should be_nil
111
+
112
+ EolScenario.load :load_more_stuff, :unique => false
113
+ $times_loads_stuff_has_been_run.should == 4 # should be run once, as it's a dependency
114
+ $times_loads_more_stuff_has_been_run.should == 1
115
+
116
+ EolScenario.load :load_stuff, :load_more_stuff, :unique => false
117
+ $times_loads_stuff_has_been_run.should == 6 # should be run twice
118
+ $times_loads_more_stuff_has_been_run.should == 2
119
+ end
120
+
121
+ it 'should be able to load multiple scenarios and run any dependencies (running each dependency only once!)' do
122
+ $times_loads_stuff_has_been_run, $times_loads_more_stuff_has_been_run = nil, nil
123
+ path = File.join File.dirname(__FILE__), '..', 'examples', 'testing_dependencies'
124
+ EolScenario.load_paths << path
125
+
126
+ EolScenario.load :load_stuff, :load_more_stuff #, :unique => true # <--- this should be the default!
127
+ $times_loads_stuff_has_been_run.should == 1 # should only run once!
128
+ $times_loads_more_stuff_has_been_run.should == 1
129
+ end
130
+
131
+ it 'should be able to load multiple scenarios' do
132
+ EolScenario.load_paths << path_to_more_scenarios
133
+
134
+ $set_by_first_scenario.should be_nil
135
+ $set_by_foo.should be_nil
136
+
137
+ EolScenario[:first, :foo].each {|scenario| scenario.load }
138
+
139
+ $set_by_first_scenario.should == 'hello from first scenario!'
140
+ $set_by_foo.should == 'hello from foo!'
141
+ end
142
+
143
+ it 'should be really easy to load multiple scenarios' do
144
+ EolScenario.load_paths << path_to_more_scenarios
145
+
146
+ $set_by_first_scenario.should be_nil
147
+ $set_by_foo.should be_nil
148
+
149
+ EolScenario.load :first, :foo
150
+
151
+ $set_by_first_scenario.should == 'hello from first scenario!'
152
+ $set_by_foo.should == 'hello from foo!'
153
+ end
154
+
155
+ it 'to_s should be the scenario name' do
156
+ EolScenario[:first].to_s.should == 'first'
157
+ end
158
+
159
+ it 'should allow globbing in load_paths' do
160
+ EolScenario.load_paths = [ File.join(File.dirname(__FILE__), '..', 'examp*', '**') ]
161
+
162
+ EolScenario.all.length.should == Dir[File.join(File.dirname(__FILE__), '..', 'examp*', '**', '*.rb')].length
163
+ EolScenario.all.map(&:name).should include('first')
164
+ EolScenario.all.map(&:name).should include('foo')
165
+ end
166
+
167
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe EolScenario::Spec do
4
+
5
+ def path_to_test_scenarios
6
+ File.join File.dirname(__FILE__), '..', 'examples', 'scenarios'
7
+ end
8
+ def path_to_additional_scenarios
9
+ File.join File.dirname(__FILE__), '..', 'examples', 'additional_scenarios'
10
+ end
11
+
12
+ before :all do
13
+ $set_by_load_me.should be_nil
14
+ $set_by_load_me_too.should be_nil
15
+ @original_scenario_paths = EolScenario.load_paths
16
+ end
17
+ after :all do
18
+ EolScenario.load_paths = @original_scenario_paths
19
+ end
20
+
21
+ scenarios :load_me, :load_me_too # <---- this is what we're testing here
22
+ # see spec_helper.rb for how to
23
+ # add this method to your app!
24
+
25
+ it 'should have the scenarios we want to try running' do
26
+ EolScenario.load_paths = [ path_to_additional_scenarios ]
27
+ EolScenario.all.length.should == 2
28
+ EolScenario.all.map(&:name).should include('load_me')
29
+ EolScenario.all.map(&:name).should include('load_me_too')
30
+ end
31
+
32
+ it 'should actually load the scenarios ok' do
33
+ $set_by_load_me.should == 'I was set by load_me'
34
+ $set_by_load_me_too.should == 'I was set by load_me_too!'
35
+ end
36
+
37
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe EolScenarios do
4
+
5
+ describe '.config' do
6
+
7
+ it 'should hold configuration settings' do
8
+ EolScenarios.config.should be_a_kind_of(Hash)
9
+ EolScenarios.config.foo = 'bar'
10
+
11
+ EolScenarios.config.foo.should == 'bar'
12
+ EolScenarios.config[:foo].should == 'bar'
13
+ EolScenarios[:foo].should == 'bar'
14
+ EolScenarios.foo.should == 'bar'
15
+ end
16
+
17
+ it 'should be able to easily reset to default values'
18
+
19
+ end
20
+
21
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'eol_scenarios'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ include EolScenario::Spec
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eol_scenarios
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 3
10
+ version: 0.3.3
11
+ platform: ruby
12
+ authors:
13
+ - Jeremy Rice
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-10 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: "Based on openrain-scenarios, q.v. Depends on hard-to-find gems at the moment: remi-indifferent-variable-hash and remi-simplecli"
38
+ email: jrice.blue@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - examples/additional_scenarios/load_me.rb
54
+ - examples/additional_scenarios/load_me_too.rb
55
+ - examples/more_scenarios/foo.rb
56
+ - examples/scenarios/first.rb
57
+ - examples/testing_dependencies/load_more_stuff.rb
58
+ - examples/testing_dependencies/load_stuff.rb
59
+ - examples/yaml_frontmatter/yaml_in_header.rb
60
+ - lib/eol_scenarios.rb
61
+ - lib/eol_scenarios/eol_scenario.rb
62
+ - lib/eol_scenarios/eol_scenarios.rb
63
+ - lib/eol_scenarios/spec.rb
64
+ - lib/eol_scenarios/tasks.rb
65
+ - rails_generators/scenario/USAGE
66
+ - rails_generators/scenario/scenario_generator.rb
67
+ - rails_generators/scenario/templates/scenario.erb
68
+ - spec/scenario_spec.rb
69
+ - spec/scenario_spec_spec.rb
70
+ - spec/scenarios_spec.rb
71
+ - spec/spec.opts
72
+ - spec/spec_helper.rb
73
+ has_rdoc: true
74
+ homepage: http://github.com/JRice/eol_scenarios
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.7
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Execute arbitrary blocks of ruby code for loading testing scenarios
107
+ test_files:
108
+ - spec/scenario_spec.rb
109
+ - spec/scenario_spec_spec.rb
110
+ - spec/scenarios_spec.rb
111
+ - spec/spec_helper.rb
112
+ - examples/additional_scenarios/load_me.rb
113
+ - examples/additional_scenarios/load_me_too.rb
114
+ - examples/more_scenarios/foo.rb
115
+ - examples/scenarios/first.rb
116
+ - examples/testing_dependencies/load_more_stuff.rb
117
+ - examples/testing_dependencies/load_stuff.rb
118
+ - examples/yaml_frontmatter/yaml_in_header.rb