Class: AcceptanceConfig

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/acceptance_test/acceptance_config.rb

Instance Method Summary collapse

Instance Method Details

#acceptance_config_fileObject



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

def acceptance_config_file
  detect_file(config_dir, "#{app_name}.yml")
end

#acceptance_data_file(name = "#{app_name}.#{format}") ⇒ Object



83
84
85
86
87
# File 'lib/acceptance_test/acceptance_config.rb', line 83

def acceptance_data_file name="#{app_name}.#{format}"
  file = detect_file(upload_dir, name)

  File.exist?(file) ? file : detect_file(data_dir, name)
end

#acceptance_results_dirObject



117
118
119
# File 'lib/acceptance_test/acceptance_config.rb', line 117

def acceptance_results_dir
  AcceptanceTest.instance.config[:results_dir]
end

#acceptance_results_fileObject



89
90
91
# File 'lib/acceptance_test/acceptance_config.rb', line 89

def acceptance_results_file
  detect_file(results_dir, "#{app_name}.#{format}")
end

#app_nameObject



55
56
57
# File 'lib/acceptance_test/acceptance_config.rb', line 55

def app_name
  ENV['APP_NAME'].nil? ? @app_name : ENV['APP_NAME']
end

#config_dirObject



67
68
69
# File 'lib/acceptance_test/acceptance_config.rb', line 67

def config_dir
  ENV['CONFIG_DIR'] ?  ENV['CONFIG_DIR'] : "acceptance_config"
end

#configure(workspace, params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/acceptance_test/acceptance_config.rb', line 13

def configure workspace, params
  @app_name = params[:app_name]

  support_dirs = load_code_from_support workspace
  load_steps support_dirs

  acceptance_test = AcceptanceTest.instance

  if params[:enable_external_source]
    data_reader = params[:data_reader] ? params[:data_reader] : default_data_reader

    acceptance_test.enable_external_source data_reader # enable external source for gherkin
  end

  acceptance_test.ignore_case_in_steps if params[:ignore_case_in_steps]

  acceptance_config = acceptance_config_file ? HashWithIndifferentAccess.new(YAML.load_file(acceptance_config_file)) : {}
  acceptance_test.configure(acceptance_config)

  if block_given?
    yield acceptance_test.config
  end

  RSpec.configure do |config|
    acceptance_test.configure_turnip turnip_report_file, turnip_report_name

    config.before(:type => :feature) do |example|
      acceptance_test.setup page, example.
    end

    config.after(:type => :feature) do |example|
       = {}

      screenshot_url_base = AcceptanceTest.instance.config[:screenshot_url_base]

      [:screenshot_url_base] = screenshot_url_base if screenshot_url_base

      acceptance_test.teardown page, example..merge(), example.exception
    end
  end
end

#data_dirObject



71
72
73
# File 'lib/acceptance_test/acceptance_config.rb', line 71

def data_dir
  ENV['DATA_DIR'] ?  ENV['DATA_DIR'] : "acceptance_data"
end

#default_data_readerObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/acceptance_test/acceptance_config.rb', line 125

def default_data_reader
  lambda do |source_path|
    path = acceptance_data_file detect_file_from_script(source_path)

    puts "Reading data from: #{path}"

    ext = File.extname(path)

    if ext == '.csv'
      CSV.read(File.expand_path(path))
    elsif ext == '.yml'
      YAML.load_file(File.expand_path(path))
    end
  end
end

#detect_file(dir, name) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/acceptance_test/acceptance_config.rb', line 141

def detect_file dir, name
  ext = File.extname(name)
  basename = File.basename(name)
  basename = basename[0..basename.size-ext.size-1]

  path1 = "#{dir}/#{basename}-#{environment}#{ext}"
  path2 = "#{dir}/#{basename}#{ext}"

  full_path1 = File.expand_path(path1)
  full_path2 = File.expand_path(path2)

  File.exist?(full_path1) ? full_path1 : full_path2
end

#detect_file_from_script(source_path) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/acceptance_test/acceptance_config.rb', line 155

def detect_file_from_script source_path
  path = source_path % {acceptance_env: environment, format: format}

  if File.exist? File.expand_path(path)
    path
  else
    dir = File.dirname(source_path)
    name = File.basename(source_path).gsub("-", '')
    source_path = (dir == ".") ? name : "#{dir}/#{name}"

    (source_path % {acceptance_env: '', format: format})
  end
end

#environmentObject



59
60
61
# File 'lib/acceptance_test/acceptance_config.rb', line 59

def environment
  ENV['ACCEPTANCE_ENV'].nil? ? "development" : ENV['ACCEPTANCE_ENV']
end

#formatObject



63
64
65
# File 'lib/acceptance_test/acceptance_config.rb', line 63

def format
  ENV['FORMAT'].nil? ? "xlsx" : ENV['FORMAT']
end

#local_env?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/acceptance_test/acceptance_config.rb', line 121

def local_env?
  !!(AcceptanceTest.instance.config[:webapp_url] =~ /localhost/)
end

#results_dirObject



75
76
77
# File 'lib/acceptance_test/acceptance_config.rb', line 75

def results_dir
  ENV['RESULTS_DIR'] ?  ENV['RESULTS_DIR'] : "acceptance_results"
end

#screenshots_dirObject



105
106
107
# File 'lib/acceptance_test/acceptance_config.rb', line 105

def screenshots_dir
  AcceptanceTest.instance.config[:screenshots_dir]
end

#turnip_report_fileObject



93
94
95
# File 'lib/acceptance_test/acceptance_config.rb', line 93

def turnip_report_file
  File.expand_path("tmp/" + (app_name ? "#{app_name}-acceptance-report.html" : "acceptance-report.html"))
end

#turnip_report_nameObject



97
98
99
# File 'lib/acceptance_test/acceptance_config.rb', line 97

def turnip_report_name
  "#{app_name[0].upcase+app_name[1..-1]} Acceptance"
end

#upload_dev_dirObject



113
114
115
# File 'lib/acceptance_test/acceptance_config.rb', line 113

def upload_dev_dir
  AcceptanceTest.instance.config[:upload_dev_dir]
end

#upload_dirObject



109
110
111
# File 'lib/acceptance_test/acceptance_config.rb', line 109

def upload_dir
  AcceptanceTest.instance.config[:upload_dir]
end

#webapp_url(name = :webapp_url) ⇒ Object



101
102
103
# File 'lib/acceptance_test/acceptance_config.rb', line 101

def webapp_url name=:webapp_url
  AcceptanceTest.instance.config[name]
end