Permalink
Browse files

Added support for default values

  • Loading branch information...
1 parent 0274fb6 commit a66039d6927a7ffbd0d41138c1db6de04c456c67 @peterhartman peterhartman committed Mar 25, 2013
Showing with 55 additions and 0 deletions.
  1. +9 −0 README.md
  2. +19 −0 features/fig_newton.feature
  3. +25 −0 features/step_definitions/fig_newton_steps.rb
  4. +2 −0 lib/fig_newton/missing.rb
View
@@ -32,6 +32,15 @@ class MyPage
end
````
+We can also supply default values which will be returned if the property does not exist:
+````ruby
+class MyPage
+ include PageObject
+
+ page_url "#{FigNewton.base_url("http://cheezyworld.com")}/my_page.html"
+end
+````
+
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:
````
@@ -53,4 +53,23 @@ Feature: Functionality of the fig_newton gem
| username | steve |
| password | secret |
+ Scenario: Requesting data that does not exist but has a default value should return the default value
+ Given I have read the configuration file
+ When I ask for a value that does not exist named "does_not_exist" that has a default value "the default value"
+ Then I should see "the default value"
+
+ Scenario: Requesting data that does not exist but has a default block should return the block result
+ Given I have read the configuration file
+ When I ask for a value that does not exist named "does_not_exist" that has a default block returning "the default value"
+ Then I should see "the default value"
+
+ Scenario: Requesting data that does not exist but has a default lambda should return the lambda result
+ Given I have read the configuration file
+ When I ask for a value that does not exist named "does_not_exist" that has a default lambda returning "the default value"
+ Then I should see "the default value"
+ And the lambda should be passed the property "does_not_exist"
+ Scenario: Requesting data that does not exist but has a default proc should return the proc result
+ Given I have read the configuration file
+ When I ask for a value that does not exist named "does_not_exist" that has a default proc returning "the default value"
+ Then I should see "the default value"
@@ -60,3 +60,28 @@
Then /^I should remove the file$/ do
File.delete("config/yaml/#{@hostname}.yml")
end
+
+When(/^I ask for a value that does not exist named "(.+)" that has a default value "(.+)"$/) do |key, value|
+ @value = FigNewton.send key, value
+end
+
+When(/^I ask for a value that does not exist named "(.+)" that has a default block returning "(.+)"$/) do |key, value|
+ @value = FigNewton.send(key) {
+ value
+ }
+end
+
+When(/^I ask for a value that does not exist named "(.+)" that has a default lambda returning "(.+)"$/) do |key, value|
+ mylambda = lambda {|property| @lambda_property = property; return value}
+ @value = FigNewton.send key, &mylambda
+end
+
+When(/^I ask for a value that does not exist named "(.+)" that has a default proc returning "(.+)"$/) do |key, value|
+ myproc = Proc.new {value}
+ @value = FigNewton.send(key, &myproc)
+end
+
+Then(/^the lambda should be passed the property "(.+)"$/) do |expected_property|
+ expect(@lambda_property).to eq(expected_property)
+end
+
@@ -6,6 +6,8 @@ def method_missing(*args, &block)
read_file unless @yml
m = args.first
value = @yml[m.to_s]
+ value = args[1] unless value
+ value = block.call(m.to_s) unless value or block.nil?
super unless value
value = FigNewton::Node.new(value) unless type_known? value
value

0 comments on commit a66039d

Please sign in to comment.