Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 61 lines (54 sloc) 1.236 kb
6d7682f @baphled Refactored FeatureFile & specs to improve the way stories where put t…
authored
1 # FeatureFile
2 # Used to handle and manipulate cucumber feature files
3 #
4 # @author Yomi Colledge
5 # @email yomi@boodah.net
6 #
c058040 @baphled Added initial steps and specs for our new FeatureFile class, which wi…
authored
7 class FeatureFile < File
8 def invalid?
2883989 @baphled Adding more specs and steps to help create our FeatureFile object
authored
9 if self.path =~ /^(.*).feature$/
c058040 @baphled Added initial steps and specs for our new FeatureFile class, which wi…
authored
10 false
11 else
12 true
13 end
14 end
2883989 @baphled Adding more specs and steps to help create our FeatureFile object
authored
15
16 def feature
d5096fa @baphled Refactored, removing most of the duplication
authored
17 read_properties /^Feature: /
2883989 @baphled Adding more specs and steps to help create our FeatureFile object
authored
18 end
0fc709e @baphled Added more functionality to the FeatureFile object
authored
19
20 def in_order
d5096fa @baphled Refactored, removing most of the duplication
authored
21 read_properties /^In order/
0fc709e @baphled Added more functionality to the FeatureFile object
authored
22 end
23
24 def i_want
d5096fa @baphled Refactored, removing most of the duplication
authored
25 read_properties /^I want/
0fc709e @baphled Added more functionality to the FeatureFile object
authored
26 end
27
28 def scenarios
29 @scenarios = [] if @scenarios.nil?
6d7682f @baphled Refactored FeatureFile & specs to improve the way stories where put t…
authored
30 self.reopen path if self.eof?
0fc709e @baphled Added more functionality to the FeatureFile object
authored
31 self.each do |line|
32 if line.strip =~ /^Scenario: /
6d7682f @baphled Refactored FeatureFile & specs to improve the way stories where put t…
authored
33 @scenarios << Story.new(:scenario => line.strip)
e8506b8 @baphled Added step for adding gathering a scenario's steps
authored
34 elsif line.strip =~ /^(Given|When|Then|And)/
6d7682f @baphled Refactored FeatureFile & specs to improve the way stories where put t…
authored
35 @scenarios.last.steps << Step.new(:title => line.strip)
0fc709e @baphled Added more functionality to the FeatureFile object
authored
36 end
37 end
38 @scenarios
39 end
e53be76 @baphled Added export method to FeatureFile, which returns a Feature object al…
authored
40
41 def export
42 Feature.new(:title => feature,
e59c0be @baphled General cleanup
authored
43 :in_order => in_order,
6d7682f @baphled Refactored FeatureFile & specs to improve the way stories where put t…
authored
44 :i_want => i_want,
45 :stories => scenarios)
e53be76 @baphled Added export method to FeatureFile, which returns a Feature object al…
authored
46 end
d5096fa @baphled Refactored, removing most of the duplication
authored
47
48 private
6d7682f @baphled Refactored FeatureFile & specs to improve the way stories where put t…
authored
49
50 # @TODO refactor to take a block, allowing us to use this method for scenarios
51 def read_properties property
52 @value = nil
53 self.reopen path
54 self.each do |line|
55 if line.strip =~ property
56 @value = line.strip
57 end
d5096fa @baphled Refactored, removing most of the duplication
authored
58 end
6d7682f @baphled Refactored FeatureFile & specs to improve the way stories where put t…
authored
59 @value
d5096fa @baphled Refactored, removing most of the duplication
authored
60 end
c058040 @baphled Added initial steps and specs for our new FeatureFile class, which wi…
authored
61 end
Something went wrong with that request. Please try again.