Permalink
Browse files

my first feature that performs an eval

  • Loading branch information...
1 parent e4a06b3 commit bbf2c17428f071296f9369229560724661b18ddf @cheezy committed Jan 21, 2012
View
@@ -12,4 +12,5 @@ guard 'cucumber', :notification => true, :cli => '--profile default' do
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
watch(%r{^lib/.+\.rb$}) { 'features' }
+ watch(%r{^features/yaml/.+$}) { 'features' }
end
@@ -1,8 +1,15 @@
Feature: Functionality of the data_magic gem
-
- Scenario: Getting basic data from the yaml
+
+ Background:
Given I have read the yaml file
When I ask for the data for "dm"
+
+ Scenario: Getting basic data from the yaml
Then the value for "value1" should be "this is value 1"
And the value for "value2" should be "this is value 2"
+ Scenario: Getting names from the yaml
+ Then the value for "full_name" should have a minimum of 2 words
+ And the value for "first_name" should be 1 word long
+ And the value for "last_name" should be 1 word long
+
@@ -7,12 +7,19 @@ class TestClass
DataMagic.load "example.yml"
end
-When /^I ask for the data for "([^\"]*)"$/ do |key|
+When /^I ask for the data for "(.+)"$/ do |key|
@data = TestClass.new.data_for key
end
-Then /^the value for "([^\"]*)" should be "([^\"]*)"$/ do |key, value|
+Then /^the value for "(.+)" should be "(.+)"$/ do |key, value|
@data[key].should == value
end
+Then /^the value for "(.+)" should be (\d+) word|words long$/ do |key, length|
+ @data[key].split(' ').size.should == length.to_i
+end
+
+Then /^the value for "(.+)" should have a minimum of (\d+) words$/ do |key, length|
+ @data[key].split(' ').size.should >= length.to_i
+end
@@ -1,4 +1,6 @@
dm:
value1: this is value 1
value2: this is value 2
-
+ full_name: ~name
+ first_name: ~first_name
+ last_name: ~last_name
View
@@ -17,7 +17,9 @@ def data_for(key)
def prep_data(data)
data.each do |key, value|
- data[key] = eval(value[1..-1]) if value[0] == "!"
+ unless value.nil?
+ data[key] = eval(value[1..-1]) if value[0] == "~"
+ end
end
data
end
@@ -21,159 +21,159 @@ def set_field_value(value)
context "translating random names" do
it "should add a name" do
Faker::Name.should_receive(:name).and_return('Joseph')
- set_field_value '!name'
+ set_field_value '~name'
example.data_for('key').should have_field_value 'Joseph'
end
it "should add first name" do
Faker::Name.should_receive(:first_name).and_return('Sam')
- set_field_value '!first_name'
+ set_field_value '~first_name'
example.data_for('key').should have_field_value 'Sam'
end
it "should add last name" do
Faker::Name.should_receive(:last_name).and_return('Smith')
- set_field_value '!last_name'
+ set_field_value '~last_name'
example.data_for('key').should have_field_value 'Smith'
end
end
context "translating random addresses" do
it "should add a street address" do
Faker::Address.should_receive(:street_address).and_return("123 Main")
- set_field_value '!street_address'
+ set_field_value '~street_address'
example.data_for('key').should have_field_value '123 Main'
end
it "should add a city" do
Faker::Address.should_receive(:city).and_return('Cleveland')
- set_field_value '!city'
+ set_field_value '~city'
example.data_for('key').should have_field_value 'Cleveland'
end
it "should add a state" do
Faker::Address.should_receive(:state).and_return('Ohio')
- set_field_value '!state'
+ set_field_value '~state'
example.data_for('key').should have_field_value 'Ohio'
end
it "should add a state abbreviation" do
Faker::Address.should_receive(:state_abbr).and_return('OH')
- set_field_value '!state_abbr'
+ set_field_value '~state_abbr'
example.data_for('key').should have_field_value 'OH'
end
it "should add a zip code" do
Faker::Address.should_receive(:zip_code).and_return('11111')
- set_field_value '!zip_code'
+ set_field_value '~zip_code'
example.data_for('key').should have_field_value '11111'
end
it "should add a country" do
Faker::Address.should_receive(:country).and_return("United States")
- set_field_value '!country'
+ set_field_value '~country'
example.data_for('key').should have_field_value 'United States'
end
it "should add a secondary address" do
Faker::Address.should_receive(:secondary_address).and_return('2nd floor')
- set_field_value '!secondary_address'
+ set_field_value '~secondary_address'
example.data_for('key').should have_field_value '2nd floor'
end
end
context "translating company names" do
it "should add a company name" do
Faker::Company.should_receive(:name).and_return('LeanDog')
- set_field_value '!company_name'
+ set_field_value '~company_name'
example.data_for('key').should have_field_value 'LeanDog'
end
end
context "translating email address" do
it "should add an email address" do
Faker::Internet.should_receive(:email).and_return('buddy@example.com')
- set_field_value '!email'
+ set_field_value '~email'
example.data_for('key').should have_field_value 'buddy@example.com'
end
end
context "translating phone numbers" do
it "shold add a phone number" do
Faker::PhoneNumber.should_receive(:phone_number).and_return('555-555-5555')
- set_field_value '!phone_number'
+ set_field_value '~phone_number'
example.data_for('key').should have_field_value '555-555-5555'
end
end
context "translating random phrases" do
it "should add a catch phrase" do
Faker::Company.should_receive(:catch_phrase).and_return('Ruby is cool')
- set_field_value '!catch_phrase'
+ set_field_value '~catch_phrase'
example.data_for('key').should have_field_value 'Ruby is cool'
end
it "should add random words" do
Faker::Lorem.should_receive(:words).and_return(['random', 'words'])
- set_field_value '!words'
+ set_field_value '~words'
example.data_for('key').should have_field_value 'random words'
end
it "should default to returning 3 words" do
- set_field_value '!words'
+ set_field_value '~words'
example.data_for('key')['field'].split.size.should == 3
end
it "should allow you to specify the number of words" do
- set_field_value '!words(4)'
+ set_field_value '~words(4)'
example.data_for('key')['field'].split.size.should == 4
end
it "should add a random sentence" do
Faker::Lorem.should_receive(:sentence).and_return('a sentence')
- set_field_value '!sentence'
+ set_field_value '~sentence'
example.data_for('key').should have_field_value 'a sentence'
end
it "should default to returning a minimum of 4 words" do
- set_field_value '!sentence'
+ set_field_value '~sentence'
example.data_for('key')['field'].split.size.should >= 4
end
it "should allow you to specify a minimum word count" do
- set_field_value '!sentence(20)'
+ set_field_value '~sentence(20)'
example.data_for('key')['field'].split.size.should >= 20
end
it "should add sentences" do
Faker::Lorem.should_receive(:sentences).and_return(['this is sentences'])
- set_field_value '!sentences'
+ set_field_value '~sentences'
example.data_for('key').should have_field_value 'this is sentences'
end
it "should default to returning a default of 3 sentences" do
- set_field_value '!sentences'
+ set_field_value '~sentences'
example.data_for('key')['field'].split('.').size.should >= 3
end
it "should allow you to specify the number of sentences" do
- set_field_value '!sentences(10)'
+ set_field_value '~sentences(10)'
example.data_for('key')['field'].split('.').size.should >= 10
end
it "should add a paragraphs" do
Faker::Lorem.should_receive(:paragraphs).and_return(['this is a paragraph'])
- set_field_value '!paragraphs'
+ set_field_value '~paragraphs'
example.data_for('key').should have_field_value 'this is a paragraph'
end
it "should return 3 paragraphs by default" do
- set_field_value '!paragraphs'
+ set_field_value '~paragraphs'
example.data_for('key')['field'].split('\n\n').size.should == 3
end
it "should allow you to specify the number of paragraphs" do
- set_field_value '!paragraphs(10)'
+ set_field_value '~paragraphs(10)'
example.data_for('key')['field'].split('\n\n').size.should == 10
end
end

0 comments on commit bbf2c17

Please sign in to comment.