circumstance 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78ceccbfc14d163bbb0f0386af65f81e6fb22779
4
- data.tar.gz: 59a0fa95a92836c3b516e704599b9c86da787add
3
+ metadata.gz: 932a87fc2d2139595d0f825a03bd8bd601bb9436
4
+ data.tar.gz: d3fcf56a5b3690ff7e38eb47f962cc0c9c327515
5
5
  SHA512:
6
- metadata.gz: 5687b3c426bc05264cd0771e98b0d59a0347dc5962204bf0207607cc3c973e50c94e74fbc0255104c5b871bba7d88920d51dbfdc4dc433246e2ae1a8bbceb346
7
- data.tar.gz: 2bc518d000c8530e1fd2a77406dd7975071ba5a96b9f03a08db4362834bd5f1c88350499a812c66221b75877c81654d1a9a8f04b4613fa84900b97b0d76e3753
6
+ metadata.gz: 00cba68c760747efca905f55cb89e1fe24103253a34870e3deef18afc95d3b480bc2aadfa319e3e20f580cbd836a9488b788521ba08716d60fa111670435dd07
7
+ data.tar.gz: 0f9e492c4582c3c87cfece1d9123192d0592b128be8c8d3e577f326ad30c5c5ac3ac5911a640f2b81aab116bb1d11754647fe834c92d1f320a12b615df9d32e7
@@ -0,0 +1,65 @@
1
+ require 'logger'
2
+
3
+ class Circumstance
4
+ autoload :Helpers, 'circumstance/helpers'
5
+ autoload :Registry, 'circumstance/registry'
6
+ autoload :VERSION, 'circumstance/version'
7
+
8
+ class << self
9
+ # Logger used for debugging information
10
+ attr_accessor :logger
11
+ # A registry which keeps track of all the circumstances 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 = Circumstance::Registry.new
21
+
22
+ def initialize(name, block)
23
+ @name, @block = name, block
24
+ end
25
+
26
+ # Returns Circumstance.logger for convenience
27
+ def logger
28
+ self.class.logger
29
+ end
30
+
31
+ # Evaluate this circumstance in the context
32
+ def evaluate(context)
33
+ logger.debug("Evaluating circumstance #{@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 circumstance on the global registry
41
+ #
42
+ # Circumstance.define(:blue_ocean_fishing) {}
43
+ def self.define(name, &block)
44
+ logger.debug("Defining circumstance #{name}")
45
+ registry.define(name, &block)
46
+ end
47
+
48
+ # Find a circumstance on the global registry
49
+ #
50
+ # Circumstance.find(:blue_ocean_fishing) #=> Proc…
51
+ def self.find(name)
52
+ registry.find(name)
53
+ end
54
+
55
+ # Find and evaluate a circumstance in a certain context. The context is usually
56
+ # either a test class or spec context.
57
+ #
58
+ # Circumstance.evaluate(self, :blue_ocean_fishing)
59
+ def self.evaluate(context, name)
60
+ logger.debug("Loading circumstance #{name}")
61
+ circumstance = find(name)
62
+ circumstance.evaluate(context)
63
+ circumstance
64
+ end
65
+ end
@@ -0,0 +1,18 @@
1
+ require 'set'
2
+
3
+ class Circumstance
4
+ module Helpers
5
+ # Returns a set of loaded circumstances for the current context
6
+ def loaded_circumstances
7
+ @loaded_circumstances ||= Set.new
8
+ end
9
+
10
+ # Evaluate a circumstance in the current context
11
+ def load_circumstance(name)
12
+ unless loaded_circumstances.include?(name)
13
+ Circumstance.evaluate(self, name)
14
+ loaded_circumstances.add(name)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ class Circumstance
2
+ # A Registry holds circumstances by name. It's usually used through Circumstance
3
+ # class methods.
4
+ class Registry
5
+ class NotFound < StandardError
6
+ end
7
+
8
+ attr_accessor :circumstances
9
+
10
+ def initialize
11
+ reset
12
+ end
13
+
14
+ # Undefine all circumstances in this Registry
15
+ def reset
16
+ @circumstances = {}
17
+ end
18
+
19
+ # Find a circumstance in this Registry by name
20
+ def find(name)
21
+ if circumstance = circumstances[name]
22
+ circumstance
23
+ else
24
+ raise Circumstance::Registry::NotFound, "Can't find the circumstance `#{name}', did you define it?"
25
+ end
26
+ end
27
+
28
+ # Define a circumstance in this Registry
29
+ def define(name, &block)
30
+ @circumstances[name] = ::Circumstance.new(name, block)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ class Circumstance
2
+ VERSION = "1.0.0"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circumstance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-23 00:00:00.000000000 Z
12
+ date: 2018-04-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -51,10 +51,10 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - LICENSE.txt
54
- - lib/scenario.rb
55
- - lib/scenario/helpers.rb
56
- - lib/scenario/registry.rb
57
- - lib/scenario/version.rb
54
+ - lib/circumstance.rb
55
+ - lib/circumstance/helpers.rb
56
+ - lib/circumstance/registry.rb
57
+ - lib/circumstance/version.rb
58
58
  homepage: http://github.com/procore/circumstance
59
59
  licenses:
60
60
  - MIT
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.5.2.1
78
+ rubygems_version: 2.5.1
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Circumstance is a thin wrapper around test setup.
@@ -1,65 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,33 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- class Scenario
2
- VERSION = "0.0.1"
3
- end