openrain-scenarios 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,22 +1,51 @@
1
- Copyright (c) 2009 OpenRain, LLC. All rights reserved.
2
-
3
- Permission is hereby granted, free of charge, to any person
4
- obtaining a copy of this software and associated documentation
5
- files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use,
7
- copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- copies of the Software, and to permit persons to whom the
9
- Software is furnished to do so, subject to the following
10
- conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
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/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ scenarios
2
+ Copyright 2009, OpenRain, LLC. All rights reserved.
3
+
4
+ This product includes software developed at OpenRain, LLC.
5
+ For further information, see http://www.openrain.com.
@@ -1,11 +1,8 @@
1
- scenarios
2
- =========
1
+ = scenarios
3
2
 
4
3
  The idea behind 'scenarios' is simple. Scenarions are basically just organized bits of arbitrary ruby code.
5
4
 
6
-
7
- why?
8
- ----
5
+ == why?
9
6
 
10
7
  Here's why scenarios were originally written ... you may use them however you wish!
11
8
 
@@ -25,9 +22,11 @@ Also, our application requires *some* data to be in the database for the app to
25
22
  load properly. So we created a scenario that loads up the minimum amount of
26
23
  data required to run the app!
27
24
 
25
+ == documentation
26
+
27
+ Read the RDoc[http://openrain.github.com/scenarios]
28
28
 
29
- how?
30
- ----
29
+ == how?
31
30
 
32
31
  $ sudo gem install remi-scenarios -s http://gems.github.com
33
32
 
@@ -44,18 +43,16 @@ to load a particular scenario ...
44
43
  $ rake scenarios:load NAME=my_scenario
45
44
  $ rake scenarios:load NAME=my_scenario,and_some_more_scenarios
46
45
 
47
-
48
- what else?
49
- ----------
46
+ == what else?
50
47
 
51
48
  more documentation to come soon!
52
49
 
50
+ == TODO
53
51
 
54
- TODO
55
- ----
56
-
57
- - i forgot to import the `scenarios` method so it's accessible from test / specs ... fix!
58
- - make the scenario directory for the generator configurable (and that dir should always be included in the Scenario loadpath
59
- - make all scenarios load within a specific context and add hooks so people can update/modify that context
60
- - 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)
61
- - make sure this works when --trace is called
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 CHANGED
@@ -8,11 +8,13 @@ begin
8
8
  Jeweler::Tasks.new do |s|
9
9
  s.name = "scenarios"
10
10
  s.summary = "Create, Organize, and Run arbitrary snippets of Ruby code"
11
- s.email = "remi@remitaylor.com"
11
+ s.email = "remi.taylor@openrain.com"
12
12
  s.homepage = "http://github.com/openrain/scenarios"
13
13
  s.description = "Create, Organize, and Run arbitrary snippets of Ruby code"
14
14
  s.authors = %w( remi )
15
15
  s.files = FileList["[A-Z]*", "{lib,spec,examples,rails_generators}/**/*"]
16
+ s.add_dependency 'remi-indifferent-variable-hash'
17
+ s.add_dependency 'remi-simplecli'
16
18
  end
17
19
  rescue LoadError
18
20
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 2
3
3
  :major: 0
4
4
  :minor: 2
@@ -1,4 +1,9 @@
1
- # i am the description
2
- # only the first line
3
- # should be included in the description
1
+ # i am the summary
2
+ #
3
+ # only the first line
4
+ # should be included in the summary
5
+ #
6
+ #no space here
7
+ #
4
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,39 @@
1
+ require 'optparse'
2
+ require 'simplecli'
3
+
4
+ class Scenarios::Bin
5
+ include SimpleCLI
6
+
7
+ def usage *args
8
+ puts <<doco
9
+
10
+ scenarios == %{ Tool For Managing and Loading Ruby Scenarios }
11
+
12
+ Usage:
13
+ scenarios command [options]
14
+
15
+ Examples:
16
+ scenarios info # ...
17
+
18
+ Further help:
19
+ scenarios commands # list all available commands
20
+ scenarios help <COMMAND> # show help for COMMAND
21
+ scenarios help # show this help message
22
+
23
+ doco
24
+ end
25
+
26
+ def info_help
27
+ <<doco
28
+ Usage: #{ script_name } info
29
+
30
+ Summary:
31
+ Display information about the scenarios currently available to you
32
+ end
33
+ doco
34
+ end
35
+ def info
36
+ puts Scenarios.info
37
+ end
38
+
39
+ end
@@ -12,11 +12,13 @@
12
12
  # actually give private methods a private visibility
13
13
  #
14
14
  class Scenario
15
+ include IndifferentVariableHash
15
16
 
16
17
  attr_accessor :file_path
17
18
 
18
19
  def initialize file_path
19
20
  @file_path = file_path
21
+ source_code # does some parsing ... eager load this! otherwise Scenario[:first].some_var won't work
20
22
  end
21
23
 
22
24
  def name
@@ -25,11 +27,11 @@ class Scenario
25
27
  alias to_s name
26
28
 
27
29
  # if the first line of the scenario's source code
28
- # is a comment, we use it as the scenario's description
30
+ # is a comment, we use it as the scenario's summary
29
31
  #
30
- # ideally, all scenarios should have a short simple description
32
+ # ideally, all scenarios should have a short simple summary
31
33
  #
32
- def description
34
+ def summary
33
35
  if first_line =~ /^#/
34
36
  first_line.sub(/^#*/, '').strip
35
37
  else
@@ -38,11 +40,27 @@ class Scenario
38
40
  end
39
41
 
40
42
  def first_line
41
- source_code.split("\n").first
43
+ header.split("\n").first #.gsub(/^#* ?/, '')
42
44
  end
43
45
 
44
46
  def source_code
45
- File.read file_path
47
+ unless @source_code
48
+ # the first time we read in the source code,
49
+ # see if there are any variables in the header
50
+ # and, if so, set them via IndifferentVariableHash
51
+ @source_code = File.read file_path
52
+ yaml_frontmatter = header.gsub(/^#* ?/, '')[/^---.*/m]
53
+ if yaml_frontmatter
54
+ require 'yaml'
55
+ header_variables = YAML::load(yaml_frontmatter)
56
+ variables.merge!(header_variables) if header_variables
57
+ end
58
+ end
59
+ @source_code
60
+ end
61
+
62
+ def description
63
+ header.gsub(/^#* ?/, '').gsub(/^---.*/m, '').strip # gets rid of comment hashes and yaml
46
64
  end
47
65
 
48
66
  # evaluates the code of the scenario
@@ -50,6 +68,11 @@ class Scenario
50
68
  self.class.load self # pass the loading off to the class
51
69
  end
52
70
 
71
+ # Comment header, any comments at the top of the source code
72
+ def header
73
+ source_code.gsub /\n^[^#].*/m, ''
74
+ end
75
+
53
76
  class << self
54
77
 
55
78
  # an array of the paths where scenarios can be found
@@ -116,20 +139,50 @@ class Scenario
116
139
  def load *scenarios
117
140
  puts "called Scenario.load with scenarios #{ scenarios.inspect }" if Scenario.verbose
118
141
  @before_blocks.each { |b| b.call } if @before_blocks and not @before_blocks.empty?
142
+
119
143
  # TODO should be able to define some block that scenarios get evaluated in!
120
144
  # or some things that scenarios might want to require or ...
145
+
146
+ options = ( scenarios.last.is_a?(Hash) ) ? scenarios.pop : { }
147
+ options[:unique] ||= true # whether each scenario passed has to be unique ... will likely change this to be true by default
148
+
149
+ # make sure everything is actually a Scenario object
150
+ scenarios.map! do |scenario|
151
+ scenario.is_a?(Scenario) ? scenario : self[scenario]
152
+ end
153
+
154
+ scenarios.compact! # get rid of any nils
155
+
156
+ scenarios = scenarios.inject([]) do |all, scenario|
157
+ all << scenario
158
+ all += Scenario[ nil, *scenario.dependencies ] if scenario.dependencies
159
+ all
160
+ end
161
+
162
+ # TODO clean up this crazy lame mess ... also, this doesn't
163
+ # guarantee order, which is a huge fail wrt dependencies!
164
+ scenarios = scenarios.inject({}) { |all, scenario|
165
+ all[ scenario.name ] = scenario
166
+ all
167
+ }.values if options[:unique]
168
+
121
169
  scenarios.each do |scenario|
122
170
  scenario = self[scenario] unless scenario.is_a?Scenario # try getting using self[] if not a scenario
123
- puts "loading #{ scenario.name } (#{ scenario.description })" if Scenario.verbose && scenario.is_a?(Scenario)
171
+ puts "loading #{ scenario.name } (#{ scenario.summary })" if Scenario.verbose && scenario.is_a?(Scenario)
124
172
  begin
125
173
  if scenario.is_a?Scenario
126
- puts "eval'ing scenario: #{ scenario.inspect }" if Scenario.verbose
127
- eval scenario.source_code
174
+ puts "loading scenario: #{ scenario.file_path }" if Scenario.verbose
175
+
176
+ # TODO update to eval ... should load in a custom context ...
177
+ # the eval should also catch exceptions and print the
178
+ # line number that threw the exception, etc etc
179
+ Kernel::load scenario.file_path
128
180
  else
129
181
  puts "Unsure how to load scenario: #{ scenario.inspect }"
130
182
  end
131
183
  rescue => ex
132
- raise "An Exception was thrown by scenario: #{ scenario.name }\n\n#{ ex }"
184
+ puts "An Exception was thrown by scenario: #{ scenario.name }"
185
+ raise ex
133
186
  end
134
187
  end
135
188
  end
@@ -0,0 +1,34 @@
1
+ # Top-level namespace for Scenarios
2
+ #
3
+ # Holds configuration for Scenarios
4
+ # and acts as a bit of a utility class,
5
+ # holding lots of methods / logic
6
+ # used by Scenarios.
7
+ #
8
+ class Scenarios
9
+ class << self
10
+
11
+ # include IndifferentVariableHash in Scenarios so we can
12
+ # get/set easily configuration settings for Scenarios
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
+ # Scenarios.config.foo
21
+ # Scenarios.config[:foo]
22
+ # Scenarios[:foo]
23
+ # Scenarios.foo
24
+ #
25
+ alias config variables
26
+
27
+ # returns a formatted string displaying
28
+ # information about the current Scenarios
29
+ # environment and conifuguration, etc etc.
30
+ def info
31
+ "hello from Scenarios#info"
32
+ end
33
+ end
34
+ end
@@ -24,8 +24,22 @@ namespace :scenarios do
24
24
  puts "called scenarios:load" if Scenario.verbose
25
25
  if ENV['NAME']
26
26
  names = ENV['NAME'].split(',')
27
- puts "Scenario.load #{ names.inspect }" if Scenario.verbose
28
- Scenario.load *names
27
+ names.each do |scenario_name|
28
+ puts "Scenario.load #{scenario_name}"
29
+ Scenario.load scenario_name
30
+ end
31
+ else
32
+ puts "you need to pass NAME=scenario_name to load a scenario"
33
+ end
34
+ end
35
+
36
+ desc 'scenarios:show NAME=foo OR NAME=a,b,c'
37
+ task :show do
38
+ if ENV['NAME']
39
+ names = ENV['NAME'].split(',')
40
+ names.each do |scenario_name|
41
+ puts "this would puts out some kindof information / description for #{ scenario_name }"
42
+ end
29
43
  else
30
44
  puts "you need to pass NAME=scenario_name to load a scenario"
31
45
  end
data/lib/scenarios.rb CHANGED
@@ -1,8 +1,15 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
+ require 'rubygems'
4
+ require 'indifferent-variable-hash'
5
+ require 'scenarios/scenarios'
3
6
  require 'scenarios/scenario'
4
7
 
8
+ # TODO not 100% sure if i want this
5
9
  Scenario.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
6
12
  Scenario.verbose = false
7
13
 
14
+ # TODO get rid of this, i think i want to *explicitly* require this
8
15
  require 'scenarios/spec' if defined? Spec
@@ -22,6 +22,11 @@ describe Scenario do
22
22
  Scenario.load_paths = @original_scenario_paths
23
23
  end
24
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
+
25
30
  it 'should find scenario files properly' do
26
31
  Scenario.load_paths = []
27
32
  Scenario.all.should be_empty
@@ -61,8 +66,23 @@ describe Scenario do
61
66
  Scenario.all.first.name.should == 'first'
62
67
  end
63
68
 
69
+ it 'should have a summary' do
70
+ Scenario.all.first.summary.should == 'i am the summary'
71
+ end
72
+
64
73
  it 'should have a description' do
65
- Scenario.all.first.description.should == 'i am the description'
74
+ Scenario.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
+ Scenario.load_paths << path
80
+
81
+ Scenario[:yaml_in_header].name.should == 'yaml_in_header'
82
+ Scenario[:yaml_in_header].summary.should == 'i have some yaml'
83
+ Scenario[:yaml_in_header].description.should == "i have some yaml\n\n hi there\n indeed i do"
84
+ Scenario[:yaml_in_header].header.should include('foo: x')
85
+ Scenario[:yaml_in_header].foo.should == 'x'
66
86
  end
67
87
 
68
88
  it 'should be loadable' do
@@ -71,6 +91,43 @@ describe Scenario do
71
91
  $set_by_first_scenario.should == 'hello from first scenario!'
72
92
  end
73
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
+ Scenario.load_paths << path
98
+
99
+ Scenario[: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
+ Scenario.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
+ Scenario.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
+ Scenario.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
+ Scenario.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
+ Scenario.load_paths << path
125
+
126
+ Scenario.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
+
74
131
  it 'should be able to load multiple scenarios' do
75
132
  Scenario.load_paths << path_to_more_scenarios
76
133
 
@@ -102,7 +159,7 @@ describe Scenario do
102
159
  it 'should allow globbing in load_paths' do
103
160
  Scenario.load_paths = [ File.join(File.dirname(__FILE__), '..', 'examp*', '**') ]
104
161
 
105
- Scenario.all.length.should == 4
162
+ Scenario.all.length.should == Dir[File.join(File.dirname(__FILE__), '..', 'examp*', '**', '*.rb')].length
106
163
  Scenario.all.map(&:name).should include('first')
107
164
  Scenario.all.map(&:name).should include('foo')
108
165
  end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Scenarios do
4
+
5
+ describe '.config' do
6
+
7
+ it 'should hold configuration settings' do
8
+ Scenarios.config.should be_a_kind_of(Hash)
9
+ Scenarios.config.foo = 'bar'
10
+
11
+ Scenarios.config.foo.should == 'bar'
12
+ Scenarios.config[:foo].should == 'bar'
13
+ Scenarios[:foo].should == 'bar'
14
+ Scenarios.foo.should == 'bar'
15
+ end
16
+
17
+ it 'should be able to easily reset to default values'
18
+
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openrain-scenarios
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - remi
@@ -9,12 +9,31 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-06 00:00:00 -08:00
12
+ date: 2009-03-05 00:00:00 -08:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: remi-indifferent-variable-hash
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: remi-simplecli
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
16
35
  description: Create, Organize, and Run arbitrary snippets of Ruby code
17
- email: remi@remitaylor.com
36
+ email: remi.taylor@openrain.com
18
37
  executables: []
19
38
 
20
39
  extensions: []
@@ -22,18 +41,27 @@ extensions: []
22
41
  extra_rdoc_files: []
23
42
 
24
43
  files:
44
+ - NOTICE
25
45
  - Rakefile
26
46
  - VERSION.yml
27
- - README.markdown
47
+ - README.rdoc
28
48
  - LICENSE
29
49
  - lib/scenarios
30
50
  - lib/scenarios/spec.rb
51
+ - lib/scenarios/bin.rb
31
52
  - lib/scenarios/scenario.rb
32
53
  - lib/scenarios/tasks.rb
54
+ - lib/scenarios/scenarios.rb
33
55
  - lib/scenarios.rb
56
+ - spec/scenarios_spec.rb
34
57
  - spec/scenario_spec.rb
35
58
  - spec/spec_helper.rb
36
59
  - spec/scenario_spec_spec.rb
60
+ - examples/yaml_frontmatter
61
+ - examples/yaml_frontmatter/yaml_in_header.rb
62
+ - examples/testing_dependencies
63
+ - examples/testing_dependencies/load_stuff.rb
64
+ - examples/testing_dependencies/load_more_stuff.rb
37
65
  - examples/scenarios
38
66
  - examples/scenarios/first.rb
39
67
  - examples/additional_scenarios