fig_newton 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.3-p194@data_magic --create
1
+ rvm 1.9.3-p392@fig_newton --create
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ === Version 0.8 / 2013-3-28
2
+ * Enhancements
3
+ * Added ability to provide default values for any element (Thanks Peter Hartman)
4
+
1
5
  === Version 0.7 / 2013-1-1
2
6
  * Enhancements
3
7
  * Added a to_hash method to Node
data/README.md CHANGED
@@ -8,7 +8,9 @@ Manages configuration for test suites. It is common to need different configura
8
8
 
9
9
  Using FigNewton is as simple as specifying the directory to use, loading a file from that directory, and then calling methods on the module that match the keys in the file. Let's look at an example.
10
10
 
11
- By default the FigNewton gem will look for files in the 'config/environments' directory. Let's assume that we have files named ci.yml, test.yml, and system_test.yml in that directory. All we need to do is call the `load` method in order to begin using a file:
11
+ By default the FigNewton gem will look for files in the 'config/environments' directory. If you wish to use a different directory you simply set the correct directory like this - `FigNewton.yml_directory = 'other_directory'`.
12
+
13
+ By default, FigNewton will read a file named `default.yml` but you can name your _yml_ files anything you want. Let's assume that we have files named ci.yml, test.yml, and system_test.yml in that directory. All we need to do is call the `load` method in order to begin using a file:
12
14
 
13
15
  ````ruby
14
16
  FigNewton.load('system_test.yml')
@@ -30,6 +32,15 @@ class MyPage
30
32
  end
31
33
  ````
32
34
 
35
+ We can also supply default values which will be returned if the property does not exist:
36
+ ````ruby
37
+ class MyPage
38
+ include PageObject
39
+
40
+ page_url "#{FigNewton.base_url("http://cheezyworld.com")}/my_page.html"
41
+ end
42
+ ````
43
+
33
44
  If you have an environment variable `FIG_NEWTON_FILE` set then it will read that file by default. This makes it easy to set the environment via your `cucumber.yml` file like this:
34
45
 
35
46
  ````
@@ -41,6 +52,8 @@ staging: FIG_NEWTON_FILE=staging.yml --color --format pretty
41
52
 
42
53
  When you run the cucumber command you can easily select the correct profile which in turn will select the correct configuration file for your environment.
43
54
 
55
+ Another way to set the file to use is to create a file based on the hostname of the computers on which it will run. For example, if we have an environment named _development.mydomain.com_ and another environment named _test.mydomain.com_ and yet another named _systemtest.mydomain.com_ we can create files named the same as the domain with the yml extension.
56
+
44
57
 
45
58
  ## Installation
46
59
 
@@ -53,4 +53,23 @@ Feature: Functionality of the fig_newton gem
53
53
  | username | steve |
54
54
  | password | secret |
55
55
 
56
+ Scenario: Requesting data that does not exist but has a default value should return the default value
57
+ Given I have read the configuration file
58
+ When I ask for a value that does not exist named "does_not_exist" that has a default value "the default value"
59
+ Then I should see "the default value"
60
+
61
+ Scenario: Requesting data that does not exist but has a default block should return the block result
62
+ Given I have read the configuration file
63
+ When I ask for a value that does not exist named "does_not_exist" that has a default block returning "the default value"
64
+ Then I should see "the default value"
65
+
66
+ Scenario: Requesting data that does not exist but has a default lambda should return the lambda result
67
+ Given I have read the configuration file
68
+ When I ask for a value that does not exist named "does_not_exist" that has a default lambda returning "the default value"
69
+ Then I should see "the default value"
70
+ And the lambda should be passed the property "does_not_exist"
56
71
 
72
+ Scenario: Requesting data that does not exist but has a default proc should return the proc result
73
+ Given I have read the configuration file
74
+ When I ask for a value that does not exist named "does_not_exist" that has a default proc returning "the default value"
75
+ Then I should see "the default value"
@@ -60,3 +60,28 @@ end
60
60
  Then /^I should remove the file$/ do
61
61
  File.delete("config/yaml/#{@hostname}.yml")
62
62
  end
63
+
64
+ When(/^I ask for a value that does not exist named "(.+)" that has a default value "(.+)"$/) do |key, value|
65
+ @value = FigNewton.send key, value
66
+ end
67
+
68
+ When(/^I ask for a value that does not exist named "(.+)" that has a default block returning "(.+)"$/) do |key, value|
69
+ @value = FigNewton.send(key) {
70
+ value
71
+ }
72
+ end
73
+
74
+ When(/^I ask for a value that does not exist named "(.+)" that has a default lambda returning "(.+)"$/) do |key, value|
75
+ mylambda = lambda {|property| @lambda_property = property; return value}
76
+ @value = FigNewton.send key, &mylambda
77
+ end
78
+
79
+ When(/^I ask for a value that does not exist named "(.+)" that has a default proc returning "(.+)"$/) do |key, value|
80
+ myproc = Proc.new {value}
81
+ @value = FigNewton.send(key, &myproc)
82
+ end
83
+
84
+ Then(/^the lambda should be passed the property "(.+)"$/) do |expected_property|
85
+ expect(@lambda_property).to eq(expected_property)
86
+ end
87
+
@@ -6,6 +6,8 @@ module FigNewton
6
6
  read_file unless @yml
7
7
  m = args.first
8
8
  value = @yml[m.to_s]
9
+ value = args[1] unless value
10
+ value = block.call(m.to_s) unless value or block.nil?
9
11
  super unless value
10
12
  value = FigNewton::Node.new(value) unless type_known? value
11
13
  value
@@ -1,3 +1,3 @@
1
1
  module FigNewton
2
- VERSION = "0.7"
2
+ VERSION = "0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fig_newton
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-01 00:00:00.000000000 Z
13
+ date: 2013-03-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: yml_reader
@@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  segments:
109
109
  - 0
110
- hash: 3950624979441891503
110
+ hash: -3441503605915492035
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  none: false
113
113
  requirements:
@@ -116,10 +116,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  segments:
118
118
  - 0
119
- hash: 3950624979441891503
119
+ hash: -3441503605915492035
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 1.8.24
122
+ rubygems_version: 1.8.25
123
123
  signing_key:
124
124
  specification_version: 3
125
125
  summary: Provides a simple mechanism to maintain and use different configurations