circumstance 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/lib/scenario.rb +65 -0
- data/lib/scenario/helpers.rb +18 -0
- data/lib/scenario/registry.rb +33 -0
- data/lib/scenario/version.rb +3 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 78ceccbfc14d163bbb0f0386af65f81e6fb22779
|
4
|
+
data.tar.gz: 59a0fa95a92836c3b516e704599b9c86da787add
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5687b3c426bc05264cd0771e98b0d59a0347dc5962204bf0207607cc3c973e50c94e74fbc0255104c5b871bba7d88920d51dbfdc4dc433246e2ae1a8bbceb346
|
7
|
+
data.tar.gz: 2bc518d000c8530e1fd2a77406dd7975071ba5a96b9f03a08db4362834bd5f1c88350499a812c66221b75877c81654d1a9a8f04b4613fa84900b97b0d76e3753
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) Procore <info@procore.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/scenario.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
class Scenario
|
4
|
+
autoload :Helpers, 'scenario/helpers'
|
5
|
+
autoload :Registry, 'scenario/registry'
|
6
|
+
autoload :VERSION, 'scenario/version'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Logger used for debugging information
|
10
|
+
attr_accessor :logger
|
11
|
+
# A registry which keeps track of all the scenarios you've defined
|
12
|
+
attr_accessor :registry
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
self.logger = Logger.new($stderr)
|
18
|
+
logger.level = Logger::ERROR
|
19
|
+
|
20
|
+
self.registry = Scenario::Registry.new
|
21
|
+
|
22
|
+
def initialize(name, block)
|
23
|
+
@name, @block = name, block
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns Scenario.logger for convenience
|
27
|
+
def logger
|
28
|
+
self.class.logger
|
29
|
+
end
|
30
|
+
|
31
|
+
# Evaluate this scenario in the context
|
32
|
+
def evaluate(context)
|
33
|
+
logger.debug("Evaluating scenario #{@name}")
|
34
|
+
if defined?(FactoryGirl)
|
35
|
+
context.send(:include, FactoryGirl::Syntax::Methods)
|
36
|
+
end
|
37
|
+
context.instance_eval(&@block)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Define a scenario on the global registry
|
41
|
+
#
|
42
|
+
# Scenario.define(:blue_ocean_fishing) {}
|
43
|
+
def self.define(name, &block)
|
44
|
+
logger.debug("Defining scenario #{name}")
|
45
|
+
registry.define(name, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Find a scenario on the global registry
|
49
|
+
#
|
50
|
+
# Scenario.find(:blue_ocean_fishing) #=> Proc…
|
51
|
+
def self.find(name)
|
52
|
+
registry.find(name)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Find and evaluate a scenario in a certain context. The context is usually
|
56
|
+
# either a test class or spec context.
|
57
|
+
#
|
58
|
+
# Scenario.evaluate(self, :blue_ocean_fishing)
|
59
|
+
def self.evaluate(context, name)
|
60
|
+
logger.debug("Loading scenario #{name}")
|
61
|
+
scenario = find(name)
|
62
|
+
scenario.evaluate(context)
|
63
|
+
scenario
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
class Scenario
|
4
|
+
module Helpers
|
5
|
+
# Returns a set of loaded scenarios for the current context
|
6
|
+
def loaded_scenarios
|
7
|
+
@loaded_scenarios ||= Set.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# Evaluate a scenario in the current context
|
11
|
+
def load_scenario(name)
|
12
|
+
unless loaded_scenarios.include?(name)
|
13
|
+
Scenario.evaluate(self, name)
|
14
|
+
loaded_scenarios.add(name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Scenario
|
2
|
+
# A Registry holds scenarios by name. It's usually used through Scenario
|
3
|
+
# class methods.
|
4
|
+
class Registry
|
5
|
+
class NotFound < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :scenarios
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
reset
|
12
|
+
end
|
13
|
+
|
14
|
+
# Undefine all scenarios in this Registry
|
15
|
+
def reset
|
16
|
+
@scenarios = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Find a scenario in this Registry by name
|
20
|
+
def find(name)
|
21
|
+
if scenario = scenarios[name]
|
22
|
+
scenario
|
23
|
+
else
|
24
|
+
raise Scenario::Registry::NotFound, "Can't find the scenario `#{name}', did you define it?"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Define a scenario in this Registry
|
29
|
+
def define(name, &block)
|
30
|
+
@scenarios[name] = ::Scenario.new(name, block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: circumstance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manfred Stienstra
|
8
|
+
- Matt Casper
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
description: |2
|
43
|
+
Circumstance allows you to register and evaluate setup block globally in your
|
44
|
+
test suite. This is useful when you want to share big blocks of factory
|
45
|
+
setups between tests.
|
46
|
+
email:
|
47
|
+
- manfred@fngtps.com
|
48
|
+
- matthewvcasper@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- LICENSE.txt
|
54
|
+
- lib/scenario.rb
|
55
|
+
- lib/scenario/helpers.rb
|
56
|
+
- lib/scenario/registry.rb
|
57
|
+
- lib/scenario/version.rb
|
58
|
+
homepage: http://github.com/procore/circumstance
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.5.2.1
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Circumstance is a thin wrapper around test setup.
|
82
|
+
test_files: []
|