ruby_flipper 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_flipper (0.0.1)
4
+ ruby_flipper (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.rdoc CHANGED
@@ -76,7 +76,7 @@ This defines a feature that is only enabled when the feature :development_featur
76
76
 
77
77
  === More
78
78
 
79
- For more examples, see spec/fixtures/features.rb and spec/ruby_flipper_spec.rb (section .load which is kind of an end-to-end integration test).
79
+ For more examples, see spec/fixtures/features.rb and spec/ruby_flipper_spec.rb (section 'integration specs using spec/fixtures/features.rb' which is an end-to-end integration test).
80
80
 
81
81
 
82
82
  == Condition Definitions
@@ -0,0 +1,18 @@
1
+ require 'ruby_flipper'
2
+ require 'rails'
3
+
4
+ module RubyFlipper
5
+
6
+ class Railtie < Rails::Railtie
7
+
8
+ initializer :initialize_ruby_flipper_config, :before => :load_config_initializers do
9
+ RubyFlipper.config[:feature_file] = Rails.root.join 'config/features.rb'
10
+ end
11
+
12
+ initializer :load_ruby_flipper_features, :after => :load_config_initializers do
13
+ RubyFlipper.load
14
+ end
15
+
16
+ end
17
+
18
+ end
data/lib/ruby_flipper.rb CHANGED
@@ -8,12 +8,25 @@ module RubyFlipper
8
8
  autoload :Dsl, 'ruby_flipper/dsl'
9
9
  autoload :Feature, 'ruby_flipper/feature'
10
10
 
11
- def self.load(file)
12
- Dsl.new.instance_eval(IO.read file)
11
+ def self.config
12
+ @@config ||= {}
13
+ end
14
+
15
+ def self.config=(config)
16
+ @@config = config
17
+ end
18
+
19
+ def self.load(file = nil)
20
+ file ||= config[:feature_file]
21
+ raise ArgumentError, 'you have to either specify or configure a feature definition file in RubyFlipper::config[:feature_file]' if file.nil?
22
+ Dsl.new.instance_eval(IO.read file) if File.exist?(file)
13
23
  end
14
24
 
15
25
  def self.reset
26
+ @@config = nil
16
27
  Feature.reset
17
28
  end
18
29
 
19
30
  end
31
+
32
+ require 'ruby_flipper/railtie' if defined?(Rails)
data/ruby_flipper.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ruby_flipper"
6
- s.version = "0.0.2"
6
+ s.version = "0.0.3"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Thomas Jachmann"]
9
9
  s.email = ["self@thomasjachmann.com"]
@@ -2,8 +2,75 @@ require 'spec_helper'
2
2
 
3
3
  describe RubyFlipper do
4
4
 
5
+ describe '.config' do
6
+
7
+ it 'should initially be an empty hash' do
8
+ RubyFlipper.config.should == {}
9
+ end
10
+
11
+ it 'should be changeable' do
12
+ RubyFlipper.config[:key] = :value
13
+ RubyFlipper.config.should == {:key => :value}
14
+ end
15
+
16
+ it 'should be overwritable' do
17
+ RubyFlipper.config[:key] = :value
18
+ RubyFlipper.config = {:another_key => :another_value}
19
+ RubyFlipper.config.should == {:another_key => :another_value}
20
+ end
21
+
22
+ end
23
+
5
24
  describe '.load' do
6
25
 
26
+ it 'should load the given file' do
27
+ File.expects(:exist?).with('features.rb').returns(true)
28
+ IO.expects(:read).with('features.rb').returns('feature :loaded_feature')
29
+ RubyFlipper.load('features.rb')
30
+ RubyFlipper::Feature.find(:loaded_feature).should be_a(RubyFlipper::Feature)
31
+ end
32
+
33
+ it 'should load the configured file when none given' do
34
+ File.expects(:exist?).with('configured_features.rb').returns(true)
35
+ IO.expects(:read).with('configured_features.rb').returns('feature :loaded_feature_from_configured')
36
+ RubyFlipper.config[:feature_file] = 'configured_features.rb'
37
+ RubyFlipper.load
38
+ RubyFlipper::Feature.find(:loaded_feature_from_configured).should be_a(RubyFlipper::Feature)
39
+ end
40
+
41
+ it 'should raise an error when a file is neither given nor configured' do
42
+ File.expects(:exist?).never
43
+ IO.expects(:read).never
44
+ lambda { RubyFlipper.load }.should raise_error ArgumentError, 'you have to either specify or configure a feature definition file in RubyFlipper::config[:feature_file]'
45
+ RubyFlipper::Feature.all.should be_empty
46
+ end
47
+
48
+ it 'should fail silently if file does not exist' do
49
+ File.expects(:exist?).with('features.rb').returns(false)
50
+ IO.expects(:read).never
51
+ RubyFlipper.load('features.rb')
52
+ RubyFlipper::Feature.all.should be_empty
53
+ end
54
+
55
+ end
56
+
57
+ describe '.reset' do
58
+
59
+ it 'should clean config hash' do
60
+ RubyFlipper.config[:key] = :value
61
+ RubyFlipper.reset
62
+ RubyFlipper.config.should == {}
63
+ end
64
+
65
+ it 'should reset features' do
66
+ RubyFlipper::Feature.expects(:reset).twice # once from here and once from spec_helper
67
+ RubyFlipper.reset
68
+ end
69
+
70
+ end
71
+
72
+ context 'integration specs using spec/fixtures/features.rb' do
73
+
7
74
  def load_features
8
75
  RubyFlipper.load(File.expand_path '../fixtures/features.rb', __FILE__)
9
76
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_flipper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thomas Jachmann
@@ -88,6 +88,7 @@ files:
88
88
  - lib/ruby_flipper/dsl.rb
89
89
  - lib/ruby_flipper/feature.rb
90
90
  - lib/ruby_flipper/object_mixin.rb
91
+ - lib/ruby_flipper/railtie.rb
91
92
  - ruby_flipper.gemspec
92
93
  - spec/fixtures/features.rb
93
94
  - spec/ruby_flipper/condition_context_spec.rb