Skip to content
Browse files

Return integer values instead of FigNewton::Node

  • Loading branch information...
1 parent 269a4f0 commit 351002377496ce5fc1578abe9e5b960055ad2ec4 @stevenjackson stevenjackson committed Nov 12, 2012
View
2 config/yaml/test_config.yml
@@ -8,3 +8,5 @@ first:
second:
third: foo
fourth: bar
+
+port: 1234
View
4 features/fig_newton.feature
@@ -34,3 +34,7 @@ Feature: Functionality of the fig_newton gem
When I ask for the value for "base_url"
Then I should see "http://cheezyworld.com"
+ Scenario: Requesting a numerical value
+ Given I have read the configuration file
+ When I ask for the value for "port"
+ Then I should see 1234
View
4 features/step_definitions/fig_newton_steps.rb
@@ -15,6 +15,10 @@
@value.should == value
end
+Then /^I should see (\d+)$/ do |value|
+ @value.should == value.to_i
+end
+
When /^I ask for a value that does not exist named "([^\"]*)"$/ do |non_existing|
@does_not_exist = non_existing
end
View
7 lib/fig_newton/missing.rb
@@ -5,13 +5,18 @@ def method_missing(*args, &block)
m = args.first
value = @yml[m.to_s]
super unless value
- value = FigNewton::Node.new(value) unless value.kind_of? String
+ value = FigNewton::Node.new(value) unless type_known? value
value
end
def read_file
@yml = YAML.load_file "#{yml_directory}/#{ENV['FIG_NEWTON_FILE']}" if ENV['FIG_NEWTON_FILE']
FigNewton.load('default.yml') unless ENV['FIG_NEWTON_FILE']
end
+
+ private
+ def type_known?(value)
+ value.kind_of? String or value.kind_of? Integer
+ end
end
end

0 comments on commit 3510023

Please sign in to comment.
Something went wrong with that request. Please try again.