appsent 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,4 +2,4 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - ree
5
- script: "bundle exec rake spec features"
5
+ script: "bundle exec rake"
data/.yardopts CHANGED
@@ -1,2 +1,3 @@
1
1
  --no-private
2
2
  --readme README.md
3
+ --files CHANGELOG.md
@@ -0,0 +1,24 @@
1
+ next release
2
+ ------------
3
+
4
+ more simple api:
5
+
6
+ mongo_db do
7
+ host String, "mongodb host" => 'localhost'
8
+ port Fixnum, "mongo port"
9
+ end
10
+
11
+ 0.0.3
12
+ -----
13
+
14
+ fixed nested parameters(issue #3)
15
+
16
+ 0.0.2
17
+ -----
18
+
19
+ issue #2 fix
20
+
21
+ 0.0.1
22
+ -----
23
+
24
+ First working protorype
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2011 kucaahbe
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -26,10 +26,8 @@ Initialize application with config requirements:
26
26
  timeout :type => Fixnum
27
27
  end
28
28
 
29
- # Array-based config(TODO:block non-required):
30
29
  exception_notification_recipients :type => Array
31
30
 
32
- my_simple_config # config without special requirements, stupid but it can do so, why not?
33
31
  end
34
32
 
35
33
  Access to config values performs in a such way:
data/Rakefile CHANGED
@@ -4,10 +4,12 @@ require 'cucumber'
4
4
  require 'cucumber/rake/task'
5
5
  Bundler::GemHelper.install_tasks
6
6
 
7
- task :default => :spec
7
+ task :default => [:spec, :features]
8
8
 
9
9
  RSpec::Core::RakeTask.new(:spec)
10
10
 
11
11
  Cucumber::Rake::Task.new(:features) do |t|
12
- t.cucumber_opts = "--format pretty"
12
+ t.profile = 'default'
13
+ t.fork = true
13
14
  end
15
+ task :cucumber => :features
@@ -0,0 +1,9 @@
1
+ <%
2
+ features=ENV['FEATURE'] || 'features'
3
+ opts = if ENV['FEATURE']
4
+ '--format pretty --tags @wip --wip'
5
+ else
6
+ '--format progress --tags ~@wip --strict'
7
+ end
8
+ %>
9
+ default: <%= [opts,features].join(' ') %>
@@ -26,10 +26,8 @@ Initialize application with config requirements:
26
26
  timeout :type => Fixnum
27
27
  end
28
28
 
29
- # Array-based config(TODO:block non-required):
30
29
  exception_notification_recipients :type => Array
31
30
 
32
- my_simple_config # config without special requirements, stupid but it can do so, why not?
33
31
  end
34
32
 
35
33
  Access to config values performs in a such way:
@@ -0,0 +1,92 @@
1
+ @wip
2
+ Feature: Array with nested params
3
+
4
+ Background:
5
+ Given a file named "my_app.rb" with:
6
+ """
7
+ require 'appsent'
8
+
9
+ AppSent.init :path => 'config', :env => 'production' do
10
+
11
+ mongodb do
12
+ host :type => String, :example => 'localhost', :desc => 'Host to connect to MongoDB'
13
+ port :type => Fixnum, :example => 27017, :desc => 'MongoDB port'
14
+
15
+ slaves :type => Array do
16
+ host :type => String, :example => 'host.com', :desc => 'mongo slave host'
17
+ port :type => Fixnum, :example => 27018, :desc => 'mongo slave port'
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ puts 'All stuff work!'
24
+ """
25
+
26
+ Scenario: Nested array parameters do not specified
27
+ When I write to "config/mongodb.yml" with:
28
+ """
29
+ production:
30
+ host: example.com
31
+ port: 27017
32
+ """
33
+ And I run `ruby my_app.rb`
34
+ Then the output should contain:
35
+ """
36
+ wrong config file 'config/mongodb.yml':
37
+ slaves: # does not exist(Array)
38
+ """
39
+
40
+ Scenario: Array parameter wrong
41
+ When I write to "config/mongodb.yml" with:
42
+ """
43
+ production:
44
+ host: example.com
45
+ port: 27017
46
+ slaves: blabla
47
+ """
48
+ And I run `ruby my_app.rb`
49
+ Then the output should contain:
50
+ """
51
+ wrong config file 'config/mongodb.yml':
52
+ slaves: blabla # wrong type,should be Array
53
+ """
54
+
55
+ Scenario: Some of array parametres wrong
56
+ When I write to "config/mongodb.yml" with:
57
+ """
58
+ production:
59
+ host: example.com
60
+ port: 27017
61
+ slaves:
62
+ - host: 100500
63
+ port: 27018
64
+ - host: sraka.com
65
+ port: blabla
66
+ """
67
+ And I run `ruby my_app.rb`
68
+ Then the output should contain:
69
+ """
70
+ wrong config file 'config/mongodb.yml':
71
+ slaves: # wrong nested array parameters
72
+ - host: 100500 # wrong type,should be String(mongo slave host)
73
+ - port: blabla # wrong type,should be Fixnum(mongo slave port)
74
+ """
75
+
76
+ Scenario: All right
77
+ When I write to "config/mongodb.yml" with:
78
+ """
79
+ production:
80
+ host: example.com
81
+ port: 27017
82
+ slaves:
83
+ - host: host1.com
84
+ port: 27018
85
+ - host: host2.com
86
+ port: 27018
87
+ """
88
+ And I run `ruby my_app.rb`
89
+ Then the output should contain:
90
+ """
91
+ All stuff work!
92
+ """
@@ -0,0 +1,66 @@
1
+ Feature: Complex usage
2
+
3
+ Background:
4
+ Given a file named "my_app.rb" with:
5
+ """
6
+ require 'appsent'
7
+
8
+ AppSent.init :path => 'config', :env => 'production' do
9
+ system_config do
10
+
11
+ google_analytics do
12
+ code :type => String, :example => 'UA-12345678-1', :desc => 'Enter your google analytics code here'
13
+ multiple_domains :type => String, :desc => 'has multiple domains?'
14
+ domain :type => String, :example => 'example.com', :desc => 'your domain'
15
+ end
16
+
17
+ system_email :type => String, :example => 'admin@example.com'
18
+
19
+ end
20
+
21
+ mongodb do
22
+ host :type => String, :example => 'localhost', :desc => 'Host to connect to MongoDB'
23
+ port :type => Fixnum, :example => 27017, :desc => 'MongoDB port'
24
+ pool_size :type => Fixnum
25
+ timeout :type => Fixnum
26
+ end
27
+
28
+ end
29
+
30
+ puts 'All stuff work!'
31
+ """
32
+ # TODO:
33
+ #recaptcha :skip_env => true do
34
+ # recaptcha_public_key :type => String, :desc => 'Recaptcha public key'
35
+ # recaptcha_private_key :type => String, :desc => 'Recaptcha private key'
36
+ #end
37
+ #notification_recipients :type => Array, :skip_env => true, :each_value => TODO
38
+ #
39
+ # slaves :type => Array do
40
+ # host :type => String, :example => 'host.com', :desc => 'mongo slave host'
41
+ # port :type => Fixnum, :example => 27018, :desc => 'mongo slave port'
42
+ # end
43
+
44
+ Scenario: All config present and have right values
45
+ When I write to "config/system_config.yml" with:
46
+ """
47
+ production:
48
+ google_analytics:
49
+ code: UA-123456
50
+ multiple_domains: 'false' # FIXME do something with boolean values
51
+ domain: gopa.sraka.com
52
+ system_email: admin@host.com
53
+ """
54
+ And I write to "config/mongodb.yml" following:
55
+ """
56
+ production:
57
+ host: 'somehost.com'
58
+ port: 27017
59
+ pool_size: 1
60
+ timeout: 5
61
+ """
62
+ And I run `ruby my_app.rb`
63
+ Then the output should contain:
64
+ """
65
+ All stuff work!
66
+ """
@@ -1,9 +1,4 @@
1
- Feature: Usage example
2
- As ruby developer
3
-
4
- I want my application to start only when all config files exist and have right values
5
-
6
- and in this case I am using appsent
1
+ Feature: Simple usage example
7
2
 
8
3
  Background:
9
4
  Given a file named "my_app.rb" with:
@@ -12,16 +7,13 @@ Feature: Usage example
12
7
 
13
8
  AppSent.init :path => 'config', :env => 'production' do
14
9
  mongodb do
15
- host :type => String, :example => 'localhost', :desc => 'Host to connect to MongoDB'
16
- port :type => Fixnum, :example => 27017, :desc => 'MongoDB port'
17
- pool_size :type => Fixnum
18
- timeout :type => Fixnum
10
+ host :type => String, :example => 'localhost', :desc => 'Host to connect to MongoDB'
11
+ port :type => Fixnum, :example => 27017, :desc => 'MongoDB port'
19
12
  end
20
13
  end
21
14
 
22
15
  puts 'All stuff work!'
23
16
  """
24
-
25
17
  Scenario: config does not exists
26
18
  When I run `ruby my_app.rb`
27
19
  Then the output should contain:
@@ -29,7 +21,7 @@ Feature: Usage example
29
21
  missing config file 'config/mongodb.yml'
30
22
  """
31
23
 
32
- Scenario: Config has no environment(or config is wrong yml file(FIXME))
24
+ Scenario: Config has no environment
33
25
  When I add file named "config/mongodb.yml"
34
26
  And I run `ruby my_app.rb`
35
27
  Then the output should contain:
@@ -49,18 +41,14 @@ Feature: Usage example
49
41
  wrong config file 'config/mongodb.yml':
50
42
  host: localhost # does not exists(Host to connect to MongoDB), String
51
43
  port: 27017 # does not exists(MongoDB port), Fixnum
52
- pool_size: # does not exists, Fixnum
53
- timeout: # does not exists, Fixnum
54
44
  """
55
45
 
56
- Scenario: Some parameter is wrong
46
+ Scenario: Some parameter is wrong type
57
47
  When I write to "config/mongodb.yml" following:
58
48
  """
59
49
  production:
60
50
  host: 100500
61
51
  port: 27017
62
- pool_size: 1
63
- timeout: 5
64
52
  """
65
53
  And I run `ruby my_app.rb`
66
54
  Then the output should contain:
@@ -75,8 +63,6 @@ Feature: Usage example
75
63
  production:
76
64
  host: 'somehost.com'
77
65
  port: 27017
78
- pool_size: 1
79
- timeout: 5
80
66
  """
81
67
  And I run `ruby my_app.rb`
82
68
  Then the output should contain:
@@ -0,0 +1,94 @@
1
+ Feature: Usage with nested params example
2
+
3
+ Background:
4
+ Given a file named "my_app.rb" with:
5
+ """
6
+ require 'appsent'
7
+
8
+ AppSent.init :path => 'config', :env => 'production' do
9
+ system_config do
10
+
11
+ google_analytics do
12
+ code :type => String, :example => 'UA-12345678-1', :desc => 'Enter your google analytics code here'
13
+ multiple_domains :type => String, :desc => 'has multiple domains?'
14
+ domain :type => String, :example => 'example.com', :desc => 'your domain'
15
+ end
16
+
17
+ end
18
+ end
19
+
20
+ puts 'All stuff work!'
21
+ """
22
+
23
+ Scenario: Nested parameters do not specified
24
+ When I write to "config/system_config.yml" with:
25
+ """
26
+ production:
27
+ blabla
28
+ """
29
+ And I run `ruby my_app.rb`
30
+ Then the output should contain:
31
+ """
32
+ wrong config file 'config/system_config.yml':
33
+ 'production' entry should contain Hash
34
+ """
35
+ When I write to "config/system_config.yml" with:
36
+ """
37
+ production:
38
+ blabla: blabla
39
+ """
40
+ And I run `ruby my_app.rb`
41
+ Then the output should contain:
42
+ """
43
+ wrong config file 'config/system_config.yml':
44
+ google_analytics: # does not exists, Hash
45
+ """
46
+
47
+ Scenario: Nested parameters does not specified
48
+ When I write to "config/system_config.yml" with:
49
+ """
50
+ production:
51
+ google_analytics:
52
+ blabla: blabla
53
+ domain: example.com
54
+ """
55
+ And I run `ruby my_app.rb`
56
+ Then the output should contain:
57
+ """
58
+ wrong config file 'config/system_config.yml':
59
+ google_analytics: # wrong nested parameters
60
+ code: UA-12345678-1 # does not exists(Enter your google analytics code here), String
61
+ multiple_domains: # does not exists(has multiple domains?), String
62
+ """
63
+
64
+ Scenario: Some nested parameters are wrong type
65
+ When I write to "config/system_config.yml" with:
66
+ """
67
+ production:
68
+ google_analytics:
69
+ code: 100500
70
+ multiple_domains: false
71
+ domain: gopa.sraka.com
72
+ """
73
+ And I run `ruby my_app.rb`
74
+ Then the output should contain:
75
+ """
76
+ wrong config file 'config/system_config.yml':
77
+ google_analytics: # wrong nested parameters
78
+ code: 100500 # wrong type,should be String(Enter your google analytics code here)
79
+ """
80
+
81
+ Scenario: All right
82
+ When I write to "config/system_config.yml" with:
83
+ """
84
+ production:
85
+ google_analytics:
86
+ code: ZZ-31234123
87
+ multiple_domains: 'false'
88
+ domain: gopa.sraka.com
89
+ """
90
+ And I run `ruby my_app.rb`
91
+ Then the output should contain:
92
+ """
93
+ All stuff work!
94
+ """
@@ -16,7 +16,7 @@ class AppSent
16
16
  end
17
17
 
18
18
  def valid?
19
- return @checked if defined?(@checked)
19
+ return @valid if defined?(@valid)
20
20
 
21
21
  yaml_data = YAML.load_file(@path_to_config)
22
22
  if yaml_data.is_a?(Hash)
@@ -24,12 +24,12 @@ class AppSent
24
24
  else
25
25
  # yaml is not valid YAML file, TODO change error message
26
26
  @self_error_msg = ENVIRONMENT_NOT_FOUND_ERROR_MSG % [relative_path_to_config,@environment]
27
- return @checked = false
27
+ return @valid = false
28
28
  end
29
29
 
30
30
  @data = yaml_data[@environment]
31
31
 
32
- @checked = if @data.instance_of?(@type)
32
+ @valid = if @data.instance_of?(@type)
33
33
  @data.symbolize_keys! if @type==Hash
34
34
  if @block
35
35
  self.instance_exec(&@block)
@@ -39,11 +39,12 @@ class AppSent
39
39
  true
40
40
  end
41
41
  else
42
+ @self_error_msg = (WRONG_CONFIG_ERROR_MSG % relative_path_to_config) + " '#{@environment}' entry should contain #{@type}"
42
43
  false
43
44
  end
44
45
  rescue Errno::ENOENT
45
46
  @self_error_msg = CONFIG_NOT_FOUND_ERROR_MSG % relative_path_to_config
46
- @checked = false
47
+ @valid = false
47
48
  end
48
49
 
49
50
  def options
@@ -7,6 +7,7 @@ class AppSent
7
7
  VALUE_NOT_EXISTS_MSG = "does not exists"
8
8
  VALUE_WRONG_TYPE_MSG = "wrong type,should be %s"
9
9
  FULL_ERROR_MESSAGE = "%s: %s # %s%s%s"
10
+ WRONG_CHILD_OPTIONS_MSG = "wrong nested parameters"
10
11
 
11
12
  # data => it's an actual data of parameter
12
13
  def initialize parameter, data_type, data, description, example, &block
@@ -14,42 +15,82 @@ class AppSent
14
15
 
15
16
  @data_type ||= Hash
16
17
  raise WRONG_DATA_TYPE_PASSED_MSG unless @data_type.is_a?(Class)
17
- raise "params #{@data_type} and block given" if block_given? and not @data_type==Hash
18
+ raise "params #{@data_type} and block given" if block_given? and not [Array,Hash].include?(@data_type)
18
19
 
19
20
  @block = block
20
21
  @nesting = 0
21
22
  end
22
23
 
23
24
  def valid?
24
- return @checked if defined?(@checked)
25
- @checked = if data.instance_of?(data_type)
26
- if @block
27
- data.symbolize_keys!
28
- self.instance_exec(&@block)
29
- child_options.any? { |option| option.valid? }
30
- else
31
- true
32
- end
33
- else
34
- false
35
- end
25
+ return @valid if defined?(@valid)
26
+
27
+ @valid = if data.instance_of?(data_type)
28
+ if @block
29
+ if data.is_a?(Array)
30
+ data.each do |data|
31
+ child_options << self.class.new(
32
+ @parameter,
33
+ Hash,
34
+ data,
35
+ @description,
36
+ @example,
37
+ &@block
38
+ )
39
+ end
40
+ else
41
+ data.symbolize_keys!
42
+ self.instance_exec(&@block)
43
+ end
44
+
45
+ @child_options_valid = child_options.ask_all? { |option| option.valid? }
46
+ else
47
+ true
48
+ end
49
+ else
50
+ false
51
+ end
36
52
  end
37
53
 
38
54
  def child_options
39
55
  @options ||= []
40
56
  end
41
57
 
58
+ def child_options_valid?
59
+ return @child_options_valid if defined?(@child_options_valid)
60
+ true
61
+ end
62
+
42
63
  def error_message
64
+ actual_data_or_example = ((data_type==Hash ? '' : data) or example)
65
+
66
+ actual_error_msg = if child_options_valid?
67
+ (data ? VALUE_WRONG_TYPE_MSG % [data_type] : VALUE_NOT_EXISTS_MSG)
68
+ else
69
+ WRONG_CHILD_OPTIONS_MSG
70
+ end
71
+
43
72
  desc = (description and "(#{description})")
44
- actual_error_msg = (data ? VALUE_WRONG_TYPE_MSG % [data_type] : VALUE_NOT_EXISTS_MSG)
73
+
45
74
  optional_type = (data ? '' : ', '+data_type.inspect)
46
- ' '*(self.nesting+1)+FULL_ERROR_MESSAGE % [parameter, (data or example), actual_error_msg, desc, optional_type]
75
+
76
+ @error_message = ' '*(self.nesting+1)+FULL_ERROR_MESSAGE % [parameter, actual_data_or_example, actual_error_msg, desc, optional_type]
77
+ if child_options_valid?
78
+ return @error_message
79
+ else
80
+ @error_message += "\n"+child_options.map { |o| o.valid? ? nil : o.error_message }.compact.join("\n")
81
+ end
47
82
  end
48
83
 
49
84
  private
50
85
 
51
86
  def method_missing option, opts={}
52
- self.child_options << self.class.new(option.to_s, opts[:type], data[option.to_sym], opts[:desc], opts[:example])
87
+ self.child_options << self.class.new(
88
+ option.to_s,
89
+ opts[:type],
90
+ data[option.to_sym],
91
+ opts[:desc],
92
+ opts[:example]
93
+ )
53
94
  self.child_options.last.nesting+=(self.nesting+1)
54
95
  end
55
96
  end
@@ -1,3 +1,3 @@
1
1
  class AppSent
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,20 +5,29 @@ describe AppSent::ConfigFile do
5
5
  subject { described_class }
6
6
 
7
7
  before :each do
8
- @params = ['/path/to/config','config_name',:environment, Hash]
9
- @fake_config_filename = '/path/to/config/config_name.yml'
8
+ @params = {
9
+ 'config_path' => '/path/to/config',
10
+ 'config_name' => 'config_name',
11
+ 'env' => :environment,
12
+ 'type' => Hash
13
+ }
14
+ end
15
+
16
+ let(:fake_config_filename) { '/path/to/config/config_name.yml' }
17
+
18
+ let(:params) do
19
+ [
20
+ @params['config_path'],
21
+ @params['config_name'],
22
+ @params['env'],
23
+ @params['type']
24
+ ]
10
25
  end
11
26
 
12
27
  context ".new" do
13
28
 
14
29
  %w(valid? options constantized error_message).each do |method|
15
- it { subject.new(*@params).should respond_to(method)}
16
- end
17
-
18
- it "should raise exception if type is not hash and block given" do
19
- block = lambda {}
20
- @params[-1] = Array
21
- expect { subject.new(*@params,&block) }.to raise_exception(/params Array and block given/)
30
+ it { subject.new(*params).should respond_to(method)}
22
31
  end
23
32
 
24
33
  end
@@ -28,22 +37,22 @@ describe AppSent::ConfigFile do
28
37
  context "should be true" do
29
38
 
30
39
  it "if config exists and environment presence(without type)(no values)" do
31
- YAML.should_receive(:load_file).once.with(@fake_config_filename).and_return('environment' => {:a=>100500})
32
- subject.new(*@params).should be_valid
40
+ YAML.should_receive(:load_file).once.with(fake_config_filename).and_return('environment' => {:a=>100500})
41
+ subject.new(*params).should be_valid
33
42
  end
34
43
 
35
44
  it "if config exists and environment presence(with type specified)(no values)" do
36
- @params[-1]=Array
37
- YAML.should_receive(:load_file).once.with(@fake_config_filename).and_return(:environment => [1,2,3])
38
- subject.new(*@params).should be_valid
45
+ @params['type']=Array
46
+ YAML.should_receive(:load_file).once.with(fake_config_filename).and_return(:environment => [1,2,3])
47
+ subject.new(*params).should be_valid
39
48
  end
40
49
 
41
50
  it "if config exists and environment presence(with values)" do
42
51
  values_block = lambda {
43
52
  value :type => String
44
53
  }
45
- YAML.should_receive(:load_file).once.with(@fake_config_filename).and_return('environment' => {:value=>'100500'})
46
- subject.new(*@params,&values_block).should be_valid
54
+ YAML.should_receive(:load_file).once.with(fake_config_filename).and_return('environment' => {:value=>'100500'})
55
+ subject.new(*params,&values_block).should be_valid
47
56
  end
48
57
 
49
58
  end
@@ -51,20 +60,20 @@ describe AppSent::ConfigFile do
51
60
  context "should be false" do
52
61
 
53
62
  it "if config does not exists" do
54
- YAML.should_receive(:load_file).once.with(@fake_config_filename).and_raise(Errno::ENOENT)
63
+ YAML.should_receive(:load_file).once.with(fake_config_filename).and_raise(Errno::ENOENT)
55
64
  end
56
65
 
57
66
  it "if environment does not presence in config" do
58
- YAML.should_receive(:load_file).once.with(@fake_config_filename).and_return('other_environment' => {:a=>100500})
67
+ YAML.should_receive(:load_file).once.with(fake_config_filename).and_return('other_environment' => {:a=>100500})
59
68
  end
60
69
 
61
70
  it "if wrong type" do
62
- @params[-1] = Array
63
- YAML.should_receive(:load_file).once.with(@fake_config_filename).and_return(:environment => 123)
71
+ @params['type'] = Array
72
+ YAML.should_receive(:load_file).once.with(fake_config_filename).and_return(:environment => 123)
64
73
  end
65
74
 
66
75
  after :each do
67
- subject.new(*@params).should_not be_valid
76
+ subject.new(*params).should_not be_valid
68
77
  end
69
78
 
70
79
  end
@@ -5,23 +5,56 @@ describe AppSent::ConfigValue do
5
5
  subject { described_class }
6
6
 
7
7
  before :each do
8
- @params = [ 'param_name', String, 'some string', 'description string', 'example string' ]
8
+ @params = {
9
+ 'name' => 'param_name',
10
+ 'type' => String,
11
+ 'value' => 'some string',
12
+ 'desc' => 'description string',
13
+ 'example' => 'example'
14
+ }
15
+ end
16
+
17
+ let(:params) do
18
+ [
19
+ @params['name'],
20
+ @params['type'],
21
+ @params['value'],
22
+ @params['desc'],
23
+ @params['example']
24
+ ]
9
25
  end
10
26
 
11
27
  context ".new" do
12
28
 
13
29
  %w(valid? child_options error_message).each do |method|
14
- it { subject.new(*@params).should respond_to(method)}
30
+ it { subject.new(*params).should respond_to(method)}
15
31
  end
16
32
 
17
33
  it "should raise exception if unsupported type passed" do
18
34
  expect { subject.new('parameter','asd','data',nil,nil) }.to raise_exception(/data type should be ruby class!/)
19
35
  end
20
36
 
21
- it "should raise exception if type is not hash and block given" do
22
- block = lambda {}
23
- @params[1] = Array
24
- expect { subject.new(*@params,&block) }.to raise_exception(/params Array and block given/)
37
+ context "with &block given" do
38
+
39
+ let(:block) do
40
+ lambda { value :type => String }
41
+ end
42
+
43
+ it "should not raise exception if data type is Array" do
44
+ @params['type'] = Array
45
+ expect { subject.new(*params,&block) }.to_not raise_exception(/params Array and block given/)
46
+ end
47
+
48
+ it "should not raise exception if data type is Hash" do
49
+ @params['type'] = Hash
50
+ expect { subject.new(*params,&block) }.to_not raise_exception(/params Hash and block given/)
51
+ end
52
+
53
+ it "should raise exception if data type is not Hash" do
54
+ @params['type'] = Fixnum
55
+ expect { subject.new(*params,&block) }.to raise_exception(/params Fixnum and block given/)
56
+ end
57
+
25
58
  end
26
59
 
27
60
  end
@@ -39,12 +72,32 @@ describe AppSent::ConfigValue do
39
72
  end
40
73
 
41
74
  it "if child value is not valid" do
42
- @params[1]=Hash
43
- @params[2]={:value => 100500}
75
+ @params['type']=Hash
76
+ @params['value']={:value => 100500}
44
77
  values_block = lambda {
45
78
  value :type => String
46
79
  }
47
- subject.new(*@params,&values_block).should_not be_valid
80
+ subject.new(*params,&values_block).should_not be_valid
81
+ end
82
+
83
+ context "with type => Array" do
84
+
85
+ it "if actual data is not array" do
86
+ @params['type']=Array
87
+ @params['value']=123
88
+ subject.new(*params).should_not be_valid
89
+ end
90
+
91
+ it "if actual data is an array of wrong hashes" do
92
+ @params['type']=Array
93
+ @params['value']=[1,2]
94
+ values_block = lambda {
95
+ value1 :type => String
96
+ value2 :type => Fixnum
97
+ }
98
+ subject.new(*params,&values_block).should_not be_valid
99
+ end
100
+
48
101
  end
49
102
 
50
103
  end
@@ -52,16 +105,33 @@ describe AppSent::ConfigValue do
52
105
  context "should return true" do
53
106
 
54
107
  it "if entry presence and has right type" do
55
- subject.new(*@params).should be_valid
108
+ subject.new(*params).should be_valid
56
109
  end
57
110
 
58
111
  it "if valid itself and child values valid too" do
59
- @params[1]=Hash
60
- @params[2]={'value' => 'some data'}
112
+ @params['type']=Hash
113
+ @params['value']={'value' => 'some data'}
61
114
  values_block = lambda {
62
115
  value :type => String
63
116
  }
64
- subject.new(*@params,&values_block).should be_valid
117
+ subject.new(*params,&values_block).should be_valid
118
+ end
119
+
120
+ context "with type => Array" do
121
+
122
+ it "if actual data is an array of right hashes" do
123
+ @params['type']=Array
124
+ @params['value']=[
125
+ {'value1' =>'qwe', 'value2' => 123 },
126
+ {'value1' =>'rty', 'value2' => 456 }
127
+ ]
128
+ values_block = lambda {
129
+ value1 :type => String
130
+ value2 :type => Fixnum
131
+ }
132
+ subject.new(*params,&values_block).should be_valid
133
+ end
134
+
65
135
  end
66
136
 
67
137
  end
metadata CHANGED
@@ -1,131 +1,108 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: appsent
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - kucaahbe
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-29 00:00:00 +03:00
12
+ date: 2011-08-02 00:00:00.000000000 +03:00
19
13
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: yard
17
+ requirement: &71364740 !ruby/object:Gem::Requirement
24
18
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
32
23
  type: :development
33
- name: yard
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
24
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *71364740
26
+ - !ruby/object:Gem::Dependency
27
+ name: BlueCloth
28
+ requirement: &71363500 !ruby/object:Gem::Requirement
38
29
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
46
34
  type: :development
47
- name: BlueCloth
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
35
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *71363500
37
+ - !ruby/object:Gem::Dependency
38
+ name: RedCloth
39
+ requirement: &71362860 !ruby/object:Gem::Requirement
52
40
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
60
45
  type: :development
61
- name: RedCloth
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
46
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *71362860
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &71361930 !ruby/object:Gem::Requirement
66
51
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 15
71
- segments:
72
- - 2
73
- - 0
74
- - 0
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
75
55
  version: 2.0.0
76
56
  type: :development
77
- name: rspec
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
57
  prerelease: false
81
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *71361930
59
+ - !ruby/object:Gem::Dependency
60
+ name: aruba
61
+ requirement: &71361640 !ruby/object:Gem::Requirement
82
62
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
90
67
  type: :development
91
- name: aruba
92
- version_requirements: *id005
93
- - !ruby/object:Gem::Dependency
94
68
  prerelease: false
95
- requirement: &id006 !ruby/object:Gem::Requirement
69
+ version_requirements: *71361640
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: &71361190 !ruby/object:Gem::Requirement
96
73
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
104
78
  type: :development
105
- name: rake
106
- version_requirements: *id006
79
+ prerelease: false
80
+ version_requirements: *71361190
107
81
  description: config management solution
108
- email:
82
+ email:
109
83
  - kucaahbe@ukr.net
110
84
  executables: []
111
-
112
85
  extensions: []
113
-
114
86
  extra_rdoc_files: []
115
-
116
- files:
87
+ files:
117
88
  - .gitignore
118
89
  - .rspec
119
90
  - .travis.yml
120
91
  - .yardopts
92
+ - CHANGELOG.md
121
93
  - Gemfile
94
+ - LICENSE.md
122
95
  - README.md
123
96
  - Rakefile
124
97
  - appsent.gemspec
98
+ - cucumber.yml
125
99
  - features/README.md
100
+ - features/array_with_nested_params.feature
101
+ - features/full_example.feature
102
+ - features/simple_usage.feature
126
103
  - features/step_definitions/helper_steps.rb
127
104
  - features/support/env.rb
128
- - features/usage_example.feature
105
+ - features/with_nested_params.feature
129
106
  - lib/appsent.rb
130
107
  - lib/appsent/config_file.rb
131
108
  - lib/appsent/config_value.rb
@@ -142,36 +119,32 @@ files:
142
119
  has_rdoc: true
143
120
  homepage: http://github.com/kucaahbe/appsent
144
121
  licenses: []
145
-
146
122
  post_install_message:
147
123
  rdoc_options: []
148
-
149
- require_paths:
124
+ require_paths:
150
125
  - lib
151
- required_ruby_version: !ruby/object:Gem::Requirement
126
+ required_ruby_version: !ruby/object:Gem::Requirement
152
127
  none: false
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- hash: 3
157
- segments:
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
158
133
  - 0
159
- version: "0"
160
- required_rubygems_version: !ruby/object:Gem::Requirement
134
+ hash: 299044573
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
136
  none: false
162
- requirements:
163
- - - ">="
164
- - !ruby/object:Gem::Version
165
- hash: 3
166
- segments:
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ segments:
167
142
  - 0
168
- version: "0"
143
+ hash: 299044573
169
144
  requirements: []
170
-
171
145
  rubyforge_project: appsent
172
146
  rubygems_version: 1.6.2
173
147
  signing_key:
174
148
  specification_version: 3
175
149
  summary: config management solution
176
150
  test_files: []
177
-