Skip to content

Commit

Permalink
Added export method to FeatureFile, which returns a Feature object al…
Browse files Browse the repository at this point in the history
…ong with its information.
  • Loading branch information
baphled committed Jan 19, 2010
1 parent 16c3234 commit e53be76
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
8 changes: 7 additions & 1 deletion features/plain/feature_files.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ Feature: We need a way to handle out feature files
Given we create a FeatureFile from a cucumber feature file
Then the object should be valid
And the object should have 1 or more scenarios
And each scenario should have the expected steps
And each scenario should have the expected steps

Scenario: A FeatureFile should be able to save a features scenarios & steps
Given we create a FeatureFile from a cucumber feature file
When a feature is valid
And it has more than one scenario
Then import will return true
13 changes: 12 additions & 1 deletion features/step_definitions/feature_file_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
@file = FeatureFile.new("#{RAILS_ROOT}/spec/fixtures/test.feature")
end

When /^a feature is valid$/ do
@file.should_not be_invalid
end

When /^it has more than one scenario$/ do
@file.scenarios.count.should >= 1
end

Then /^the object should be valid$/ do
@file.should_not be_invalid
Expand Down Expand Up @@ -33,4 +40,8 @@

Then /^each scenario should have the expected steps$/ do
@file.scenarios.first[:steps].should_not be_nil
end
end

Then /^import will return true$/ do
@file.export.should be_true
end
7 changes: 6 additions & 1 deletion lib/feature_file.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class FeatureFile < File

def invalid?
if self.path =~ /^(.*).feature$/
false
Expand Down Expand Up @@ -43,4 +42,10 @@ def scenarios
end
@scenarios
end

def export
Feature.new(:title => feature,
:in_order => in_order,
:i_want => i_want)
end
end
20 changes: 18 additions & 2 deletions spec/models/feature_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe FeatureFile do
before(:each) do
@feature_file = FeatureFile.new("#{RAILS_ROOT}/spec/fixtures/projects.yml")
@feature_file = FeatureFile.open("#{RAILS_ROOT}/spec/fixtures/projects.yml")
end

it "should be a child of the File object" do
Expand All @@ -17,7 +17,7 @@

context "a valid feature file" do
before(:each) do
@feature_file = FeatureFile.new("#{RAILS_ROOT}/spec/fixtures/test.feature")
@feature_file = FeatureFile.open("#{RAILS_ROOT}/spec/fixtures/test.feature")
end

it "should be a cucumber feature file" do
Expand Down Expand Up @@ -52,4 +52,20 @@
@feature_file.scenarios.first[:steps].count.should eql 3
end
end

context "exporting the feature files information" do

it "return the features title" do
@feature_file.export.should be_a Feature
end

it "should return the in order property " do
@feature_file.export.in_order.should_not be_nil
end

it "should return the i want property" do
@feature_file.export.i_want.should_not be_nil
end

end
end

0 comments on commit e53be76

Please sign in to comment.