Class: Suite

Inherits:
Object
  • Object
show all
Defined in:
lib/suite.rb

Direct Known Subclasses

ObjcSuite, RailsSuite

Instance Method Summary collapse

Instance Method Details

#all_feature_filesObject



105
106
107
108
109
110
111
112
113
# File 'lib/suite.rb', line 105

def all_feature_files
  all_entries_in_feature_files_path = Dir.new(feature_files_path).entries
  feature_entries =  all_entries_in_feature_files_path.select do |file|
    !!(file =~ /\.#{feature_file_suffix}$/)
  end
  feature_entries.map do |file|
    feature_files_path + "/" + file
  end
end

#all_feature_files_as_stringsObject



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/suite.rb', line 115

def all_feature_files_as_strings
  feature_files.map do |file|
    feature_string = ""
    File.open(file) do |f|
      f.readlines.each do |l|
        feature_string << l
      end
    end
    feature_string
  end
end

#htmlObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/suite.rb', line 42

def html
  <<-END
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  <html>
    <head>
      <style type="text/css">
      body { 
        font-family: Lucida Grande;
        background-color: #FEFEFE;
        padding: 5px;
      }
      * {-webkit-border-radius: 10px;}
      body {background-color: #EEE; -webkit-border-radius: 0px;}
      .feature { background-color: #E0E0E0;padding: 20px; margin: 20px;}
      .scenario { background-color: #EEE; padding: 20px; margin: 20px}
      .failed {border: 1px solid #C88; background-color: #B77; }
      .passed {border: 1px solid #8C8; background-color: #7B7; }
      .feature_title {font-size: 24pt; }
      .story { font-size: 18pt; padding-left: 40px;}
      #indicator { width: 100%; height: 20px; }
      #wrap { background-color: #EEE; padding: 20px }
      </style></head>
    </head>
    <body>
    <div id="wrap">
      <div id="header">
        <div id="indicator" class="#{passed? ? "passed" : "failed"}">&nbsp;</div>
        <h1 class="project_name">#{project_name}</h1>
        
      </div>
      #{features.map {|f| f.to_html }.join(" \n")}
    </div>
    </body>
  </html>
  END
end

#open_in_safari(html) ⇒ Object



22
23
24
# File 'lib/suite.rb', line 22

def open_in_safari(html)
  %x(touch '/tmp/out.html' && echo '#{html}' > /tmp/out.html && open '/tmp/out.html' )
end

#parseObject



94
95
96
97
# File 'lib/suite.rb', line 94

def parse
  parse_features
  parse_feature_scenarios
end

#parse_feature_scenariosObject



99
100
101
102
103
# File 'lib/suite.rb', line 99

def parse_feature_scenarios
  features.each do |feature|
    feature.parse_scenarios
  end
end

#parse_output_file_and_open_in_browser(file) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/suite.rb', line 4

def parse_output_file_and_open_in_browser(file)
  results = ""
  File.open(file) do |f|
    f.readlines.each do |l|
      results << l
    end
  end
  
  html = parse_results(results).html

  %x(touch '/tmp/out.html' && echo '#{html}' > /tmp/out.html && open '/tmp/out.html' ) 
end

#parse_results(results = "") ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/suite.rb', line 26

def parse_results(results="")
  parse
  @passed = true
  features.each do |f|
    f.scenarios.each do |s|
      s.verify_status(results)
      @passed &&= s.passed?
    end
  end
  self
end

#parse_results_and_open_in_safari(results) ⇒ Object



17
18
19
20
# File 'lib/suite.rb', line 17

def parse_results_and_open_in_safari(results)
  html = parse_results(results).html
  open_in_safari(html)
end

#passed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/suite.rb', line 38

def passed?
  @passed
end

#runObject



88
89
90
91
92
# File 'lib/suite.rb', line 88

def run
  parse
  raise "Invalid: Duplicated Titles" unless valid?
  File.open(test_cases_file, "w") { |f| f.puts self }
end

#unique_feature_test_case_names?Boolean

Returns:

  • (Boolean)


83
84
85
86
# File 'lib/suite.rb', line 83

def unique_feature_test_case_names?
  feature_test_case_name =  features.map {|f| f.test_case_name }
  feature_test_case_name == feature_test_case_name.uniq
end

#valid?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/suite.rb', line 79

def valid?
  unique_feature_test_case_names?
end