cornucopia 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +51 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +16 -0
  6. data/LICENSE.TXT +22 -0
  7. data/README.md +341 -0
  8. data/Rakefile +18 -0
  9. data/cornucopia.gemspec +39 -0
  10. data/lib/cornucopia.rb +18 -0
  11. data/lib/cornucopia/capybara/finder_diagnostics.rb +536 -0
  12. data/lib/cornucopia/capybara/finder_extensions.rb +89 -0
  13. data/lib/cornucopia/capybara/install_finder_extensions.rb +105 -0
  14. data/lib/cornucopia/capybara/install_matcher_extensions.rb +39 -0
  15. data/lib/cornucopia/capybara/matcher_extensions.rb +83 -0
  16. data/lib/cornucopia/capybara/page_diagnostics.rb +228 -0
  17. data/lib/cornucopia/cucumber_hooks.rb +38 -0
  18. data/lib/cornucopia/factory_girl/dynamic_association.rb +14 -0
  19. data/lib/cornucopia/rspec_hooks.rb +37 -0
  20. data/lib/cornucopia/site_prism/element_extensions.rb +273 -0
  21. data/lib/cornucopia/site_prism/install_element_extensions.rb +23 -0
  22. data/lib/cornucopia/site_prism/page_application.rb +126 -0
  23. data/lib/cornucopia/source_files/collapse.gif +0 -0
  24. data/lib/cornucopia/source_files/cornucopia.css +162 -0
  25. data/lib/cornucopia/source_files/expand.gif +0 -0
  26. data/lib/cornucopia/source_files/index_base.html +10 -0
  27. data/lib/cornucopia/source_files/index_contents.html +2 -0
  28. data/lib/cornucopia/source_files/more_info.js +87 -0
  29. data/lib/cornucopia/source_files/report_base.html +10 -0
  30. data/lib/cornucopia/source_files/report_contents.html +3 -0
  31. data/lib/cornucopia/spinach_hooks.rb +51 -0
  32. data/lib/cornucopia/util/configuration.rb +493 -0
  33. data/lib/cornucopia/util/configured_report.rb +520 -0
  34. data/lib/cornucopia/util/file_asset.rb +46 -0
  35. data/lib/cornucopia/util/generic_settings.rb +37 -0
  36. data/lib/cornucopia/util/log_capture.rb +97 -0
  37. data/lib/cornucopia/util/pretty_formatter.rb +580 -0
  38. data/lib/cornucopia/util/report_builder.rb +474 -0
  39. data/lib/cornucopia/util/report_formatters.rb +11 -0
  40. data/lib/cornucopia/util/report_table.rb +195 -0
  41. data/lib/cornucopia/version.rb +3 -0
  42. data/lib/tasks/cornucopia_tasks.rake +4 -0
  43. data/spec/dummy/README.rdoc +28 -0
  44. data/spec/dummy/Rakefile +6 -0
  45. data/spec/dummy/app/assets/images/.keep +0 -0
  46. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  47. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  48. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  49. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  50. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  51. data/spec/dummy/app/mailers/.keep +0 -0
  52. data/spec/dummy/app/models/.keep +0 -0
  53. data/spec/dummy/app/models/concerns/.keep +0 -0
  54. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  55. data/spec/dummy/bin/bundle +3 -0
  56. data/spec/dummy/bin/rails +4 -0
  57. data/spec/dummy/bin/rake +4 -0
  58. data/spec/dummy/config.ru +4 -0
  59. data/spec/dummy/config/application.rb +27 -0
  60. data/spec/dummy/config/boot.rb +5 -0
  61. data/spec/dummy/config/cucumber.yml +8 -0
  62. data/spec/dummy/config/database.yml +37 -0
  63. data/spec/dummy/config/environment.rb +5 -0
  64. data/spec/dummy/config/environments/development.rb +29 -0
  65. data/spec/dummy/config/environments/production.rb +80 -0
  66. data/spec/dummy/config/environments/test.rb +36 -0
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  69. data/spec/dummy/config/initializers/inflections.rb +16 -0
  70. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  71. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  72. data/spec/dummy/config/initializers/session_store.rb +3 -0
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/spec/dummy/config/locales/en.yml +23 -0
  75. data/spec/dummy/config/routes.rb +56 -0
  76. data/spec/dummy/db/schema.rb +16 -0
  77. data/spec/dummy/features/support/env.rb +66 -0
  78. data/spec/dummy/lib/assets/.keep +0 -0
  79. data/spec/dummy/lib/tasks/cucumber.rake +65 -0
  80. data/spec/dummy/public/404.html +58 -0
  81. data/spec/dummy/public/422.html +58 -0
  82. data/spec/dummy/public/500.html +57 -0
  83. data/spec/dummy/public/favicon.ico +0 -0
  84. data/spec/dummy/script/cucumber +10 -0
  85. data/spec/fixtures/sample_page.html +150 -0
  86. data/spec/lib/capybara/finder_diagnostics_spec.rb +517 -0
  87. data/spec/lib/capybara/finder_extensions_spec.rb +328 -0
  88. data/spec/lib/capybara/page_diagnostics_spec.rb +277 -0
  89. data/spec/lib/site_prism/element_extensions_spec.rb +290 -0
  90. data/spec/lib/site_prism/page_application_spec.rb +81 -0
  91. data/spec/lib/util/configuration_spec.rb +254 -0
  92. data/spec/lib/util/configured_report_spec.rb +1058 -0
  93. data/spec/lib/util/file_asset_spec.rb +86 -0
  94. data/spec/lib/util/generic_settings_spec.rb +48 -0
  95. data/spec/lib/util/log_capture_spec.rb +151 -0
  96. data/spec/lib/util/pretty_formatter_spec.rb +694 -0
  97. data/spec/lib/util/report_builder_spec.rb +983 -0
  98. data/spec/lib/util/report_formatters_spec.rb +13 -0
  99. data/spec/lib/util/report_table_exception_spec.rb +21 -0
  100. data/spec/lib/util/report_table_spec.rb +319 -0
  101. data/spec/pages/cornucopia_report_app.rb +10 -0
  102. data/spec/pages/google/email_page.rb +22 -0
  103. data/spec/pages/google/login_page.rb +25 -0
  104. data/spec/rails_helper.rb +43 -0
  105. data/spec/sample_report.rb +45 -0
  106. data/spec/spec_helper.rb +81 -0
  107. metadata +410 -0
@@ -0,0 +1,290 @@
1
+ require "spec_helper"
2
+ require ::File.expand_path("../../../lib/cornucopia/site_prism/element_extensions", File.dirname(__FILE__))
3
+
4
+ describe "SitePrism element_extensions" do
5
+ class TestPage < ::SitePrism::Page
6
+ end
7
+
8
+ class TestSection < ::SitePrism::Section
9
+ end
10
+
11
+ [TestSection, TestPage].sample(2).each do |test_class|
12
+ describe "#{test_class.name}" do
13
+ let(:pre_name) { Faker::Lorem.word }
14
+ let(:element_names) { Faker::Lorem.words(rand(3..10)).map(&:to_sym) }
15
+ let(:class_element_names) { element_names + rand(3..10).times.map(Faker::Lorem.words(rand(2..3).join("-"))) }
16
+ let(:increment) { rand(2..10) }
17
+ let(:start_index) { rand(2..10) }
18
+ let(:options) do
19
+ Faker::Lorem.words(rand(3..10)).reduce({}) do |hash, option_name|
20
+ hash[option_name] = Faker::Lorem.word
21
+ hash
22
+ end
23
+ end
24
+
25
+ describe "#patterned_elements" do
26
+ it "works" do
27
+ expect { test_class.send(:patterned_elements, "\##{pre_name}-%{element_name}", :element_1, :element_2) }.
28
+ not_to raise_exception
29
+ end
30
+
31
+ it "requires %{element_name} in the pattern" do
32
+ expect { test_class.send(:patterned_elements, "\##{pre_name}-", :element_1, :element_2) }.to raise_exception
33
+ end
34
+
35
+ it "works for 1 element" do
36
+ expect(test_class).to receive(:element).with(element_names[0], "\##{pre_name}-#{element_names[0]}")
37
+
38
+ test_class.send(:patterned_elements, "\##{pre_name}-%{element_name}", element_names[0])
39
+ end
40
+
41
+ it "calls element once for each element_name" do
42
+ element_names.each do |element_name|
43
+ expect(test_class).to receive(:element).with(element_name, "\##{pre_name}-#{element_name}")
44
+ end
45
+
46
+ test_class.send(:patterned_elements, "\##{pre_name}-%{element_name}", *element_names)
47
+ end
48
+
49
+ it "converts -'s to _" do
50
+ element_names.each do |element_name|
51
+ expect(test_class).to receive(:element).with(element_name.to_s.gsub("-", "_").to_sym,
52
+ "\##{pre_name}-#{element_name}")
53
+ end
54
+
55
+ test_class.send(:patterned_elements, "\##{pre_name}-%{element_name}", *element_names)
56
+ end
57
+
58
+ it "calls elements once for each element_name if element_array: true" do
59
+ element_names.each do |element_name|
60
+ expect(test_class).to receive(:elements).with(:xpath, element_name, "\##{pre_name}-#{element_name}")
61
+ end
62
+
63
+ test_class.send(:patterned_elements,
64
+ "\##{pre_name}-%{element_name}",
65
+ *element_names,
66
+ find_type: :xpath,
67
+ element_array: true)
68
+ end
69
+
70
+ it "passes in :find_type" do
71
+ element_names.each do |element_name|
72
+ expect(test_class).to receive(:element).with(:xpath, element_name, "\##{pre_name}-#{element_name}")
73
+ end
74
+
75
+ test_class.send(:patterned_elements, "\##{pre_name}-%{element_name}", *element_names, find_type: :xpath)
76
+ end
77
+
78
+ it "passes in options" do
79
+ element_names.each do |element_name|
80
+ expect(test_class).to receive(:element).with(:xpath, element_name, "\##{pre_name}-#{element_name}", options)
81
+ end
82
+
83
+ test_class.send(:patterned_elements,
84
+ "\##{pre_name}-%{element_name}",
85
+ *element_names,
86
+ find_type: :xpath,
87
+ additional_options: options)
88
+ end
89
+ end
90
+
91
+ describe "#form_elements" do
92
+ it "calls once per form item" do
93
+ element_names.each do |element_name|
94
+ expect(test_class).to receive(:element).with(element_name, "\##{pre_name}_#{element_name}")
95
+ end
96
+
97
+ test_class.send(:form_elements, pre_name.to_sym, *element_names)
98
+ end
99
+
100
+ it "calls elements once per form item" do
101
+ element_names.each do |element_name|
102
+ expect(test_class).to receive(:elements).with(element_name, "\##{pre_name}_#{element_name}")
103
+ end
104
+
105
+ test_class.send(:form_elements, pre_name.to_sym, *element_names, element_array: true)
106
+ end
107
+
108
+ it "ignores other options" do
109
+ element_names.each do |element_name|
110
+ expect(test_class).to receive(:elements).with(element_name, "\##{pre_name}_#{element_name}")
111
+ end
112
+
113
+ test_class.send(:form_elements, pre_name.to_sym, *element_names, find_type: :xpath, element_array: true)
114
+ end
115
+ end
116
+
117
+ describe "#id_elements" do
118
+ it "calls once per form item" do
119
+ element_names.each do |element_name|
120
+ expect(test_class).to receive(:element).with(element_name, "\##{element_name}")
121
+ end
122
+
123
+ test_class.send(:id_elements, *element_names)
124
+ end
125
+
126
+ it "calls elements once per form item" do
127
+ element_names.each do |element_name|
128
+ expect(test_class).to receive(:elements).with(element_name, "\##{element_name}")
129
+ end
130
+
131
+ test_class.send(:id_elements, *element_names, element_array: true)
132
+ end
133
+
134
+ it "ignores other options" do
135
+ element_names.each do |element_name|
136
+ expect(test_class).to receive(:elements).with(element_name, "\##{element_name}")
137
+ end
138
+
139
+ test_class.send(:id_elements, *element_names, find_type: :xpath, element_array: true)
140
+ end
141
+ end
142
+
143
+ describe "#class_elements" do
144
+ it "calls once per form item" do
145
+ element_names.each do |element_name|
146
+ expect(test_class).to receive(:element).with(element_name, ".#{element_name}")
147
+ end
148
+
149
+ test_class.send(:class_elements, *element_names)
150
+ end
151
+
152
+ it "calls elements once per form item" do
153
+ element_names.each do |element_name|
154
+ expect(test_class).to receive(:elements).with(element_name, ".#{element_name}")
155
+ end
156
+
157
+ test_class.send(:class_elements, *element_names, element_array: true)
158
+ end
159
+
160
+ it "ignores other options" do
161
+ element_names.each do |element_name|
162
+ expect(test_class).to receive(:elements).with(element_name, ".#{element_name}")
163
+ end
164
+
165
+ test_class.send(:class_elements, *element_names, find_type: :xpath, element_array: true)
166
+ end
167
+ end
168
+
169
+ describe "#indexed_elements" do
170
+ it "works" do
171
+ expect { test_class.send(:indexed_elements, "\##{pre_name}-%{element_index}", :element_1, :element_2) }.
172
+ not_to raise_exception
173
+ end
174
+
175
+ it "requires %{element_name} in the pattern" do
176
+ expect { test_class.send(:indexed_elements, "\##{pre_name}-", :element_1, :element_2) }.to raise_exception
177
+ end
178
+
179
+ it "requires an increment" do
180
+ expect { test_class.send(:indexed_elements, "\##{pre_name}-", :element_1, :element_2, increment: 0) }.
181
+ to raise_exception
182
+ end
183
+
184
+ it "works for 1 element" do
185
+ expect(test_class).to receive(:element).with(element_names[0], "\##{pre_name}-1")
186
+
187
+ test_class.send(:indexed_elements, "\##{pre_name}-%{element_index}", element_names[0])
188
+ end
189
+
190
+ it "calls element once for each element_name" do
191
+ element_names.each_with_index do |element_name, index|
192
+ expect(test_class).to receive(:element).with(element_name, "\##{pre_name}-#{index + 1}")
193
+ end
194
+
195
+ test_class.send(:indexed_elements, "\##{pre_name}-%{element_index}", *element_names)
196
+ end
197
+
198
+ it "increments the counter" do
199
+ element_names.each_with_index do |element_name, index|
200
+ expect(test_class).to receive(:element).with(element_name, "\##{pre_name}-#{(increment * index) + 1}")
201
+ end
202
+
203
+ test_class.send(:indexed_elements, "\##{pre_name}-%{element_index}", *element_names, increment: increment)
204
+ end
205
+
206
+ it "can start anywhere" do
207
+ element_names.each_with_index do |element_name, index|
208
+ expect(test_class).to receive(:element).with(element_name, "\##{pre_name}-#{start_index + (increment * index)}")
209
+ end
210
+
211
+ test_class.send(:indexed_elements,
212
+ "\##{pre_name}-%{element_index}",
213
+ *element_names,
214
+ increment: increment,
215
+ start_index: start_index)
216
+ end
217
+
218
+ it "passes in :find_type" do
219
+ element_names.each_with_index do |element_name, index|
220
+ expect(test_class).to receive(:element).
221
+ with(:xpath, element_name, "\##{pre_name}-#{start_index + (increment * index)}")
222
+ end
223
+
224
+ test_class.send(:indexed_elements,
225
+ "\##{pre_name}-%{element_index}",
226
+ *element_names,
227
+ increment: increment,
228
+ start_index: start_index,
229
+ find_type: :xpath)
230
+ end
231
+
232
+ it "passes in options" do
233
+ element_names.each_with_index do |element_name, index|
234
+ expect(test_class).to receive(:element).
235
+ with(:xpath, element_name, "\##{pre_name}-#{start_index + (increment * index)}", options)
236
+ end
237
+
238
+ test_class.send(:indexed_elements,
239
+ "\##{pre_name}-%{element_index}",
240
+ *element_names,
241
+ increment: increment,
242
+ start_index: start_index,
243
+ find_type: :xpath,
244
+ additional_options: options)
245
+ end
246
+
247
+ it "calls elements if element_array is true" do
248
+ element_names.each_with_index do |element_name, index|
249
+ expect(test_class).to receive(:elements).
250
+ with(:xpath, element_name, "\##{pre_name}-#{start_index + (increment * index)}", options)
251
+ end
252
+
253
+ test_class.send(:indexed_elements,
254
+ "\##{pre_name}-%{element_index}",
255
+ *element_names,
256
+ increment: increment,
257
+ start_index: start_index,
258
+ find_type: :xpath,
259
+ additional_options: options,
260
+ element_array: true)
261
+ end
262
+
263
+ it "skips blanks" do
264
+ skip_pos = rand(1..element_names.length - 2)
265
+ element_names[0..skip_pos - 1].each_with_index do |element_name, index|
266
+ expect(test_class).to receive(:elements).
267
+ with(:xpath, element_name, "\##{pre_name}-#{start_index + (increment * index)}", options)
268
+ end
269
+ element_names[skip_pos..-1].each_with_index do |element_name, index|
270
+ expect(test_class).to receive(:elements).
271
+ with(:xpath, element_name, "\##{pre_name}-#{1 + start_index + (increment * (skip_pos + index))}", options)
272
+ end
273
+
274
+ test_array = element_names[0..skip_pos - 1]
275
+ test_array << :__skip__
276
+ test_array += element_names[skip_pos..-1]
277
+
278
+ test_class.send(:indexed_elements,
279
+ "\##{pre_name}-%{element_index}",
280
+ *test_array,
281
+ increment: increment,
282
+ start_index: start_index,
283
+ find_type: :xpath,
284
+ additional_options: options,
285
+ element_array: true)
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
@@ -0,0 +1,81 @@
1
+ require "spec_helper"
2
+ require ::File.expand_path("../../../lib/cornucopia/site_prism/page_application", File.dirname(__FILE__))
3
+
4
+ describe Cornucopia::SitePrism::PageApplication do
5
+ class SimpleTestApplicationClass < Cornucopia::SitePrism::PageApplication
6
+ end
7
+
8
+ class TestApplicationClass < Cornucopia::SitePrism::PageApplication
9
+ def pages_module
10
+ TestModule
11
+ end
12
+ end
13
+
14
+ class Object
15
+ def method_missing(method_sym, *arguments, &block)
16
+ if method_sym == :___stupid_missing_message
17
+ "Missing message"
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ def respond_to?(method_sym, include_private = false)
24
+ if method_sym == :___stupid_missing_message
25
+ true
26
+ else
27
+ super
28
+ end
29
+ end
30
+ end
31
+
32
+ module TestModule
33
+ class TestClassPage < ::SitePrism::Page
34
+ set_url "https://www.google.com"
35
+ end
36
+
37
+ module SubTestModule
38
+ class TestClassPage < ::SitePrism::Page
39
+ set_url "https://www.facebook.com"
40
+ end
41
+ end
42
+ end
43
+
44
+ it "returns a memoized instance of the derived class" do
45
+ class_instance = TestApplicationClass.current_instance
46
+ expect(class_instance.object_id).to be == TestApplicationClass.current_instance.object_id
47
+ expect(class_instance).to be_a(TestApplicationClass)
48
+ end
49
+
50
+ it "should return #pages_module" do
51
+ expect(TestApplicationClass.pages_module).to be == TestModule
52
+ end
53
+
54
+ it "does not recognize non instance or class functions that are not pages" do
55
+ expect { TestApplicationClass.send(Faker::Lorem.word) }.to raise_error(NoMethodError)
56
+ end
57
+
58
+ it "does return a simple page object" do
59
+ expect(TestApplicationClass.test_class_page).to be_a(TestModule::TestClassPage)
60
+ end
61
+
62
+ it "does return a sub_module page object" do
63
+ expect(TestApplicationClass.sub_test_module__test_class_page).to be_a(TestModule::SubTestModule::TestClassPage)
64
+ end
65
+
66
+ it "has a default #page_module" do
67
+ expect(SimpleTestApplicationClass.pages_module).to be == Object
68
+ end
69
+
70
+ it "calls respond_to? of the parent" do
71
+ expect(SimpleTestApplicationClass.respond_to?(:yaml_tag)).to be_truthy
72
+ end
73
+
74
+ it "calls respond_to? of the instance" do
75
+ expect(SimpleTestApplicationClass.respond_to?(:to_yaml)).to be_truthy
76
+ end
77
+
78
+ it "calls method_missing of the instance" do
79
+ expect(TestApplicationClass.___stupid_missing_message).to be == "Missing message"
80
+ end
81
+ end
@@ -0,0 +1,254 @@
1
+ require "spec_helper"
2
+ require ::File.expand_path("../../../lib/cornucopia/util/configuration", File.dirname(__FILE__))
3
+
4
+ describe "Cornucopia::Util::Configuration" do
5
+ it "has a default seed value" do
6
+ expect(Cornucopia::Util::Configuration.seed).not_to be
7
+ end
8
+
9
+ it "can set the seed value" do
10
+ begin
11
+ seed_value = rand(0..999999999999999999999999999)
12
+
13
+ Cornucopia::Util::Configuration.seed = seed_value
14
+
15
+ expect(Cornucopia::Util::Configuration.seed).to be == seed_value
16
+ ensure
17
+ Cornucopia::Util::Configuration.seed = nil
18
+ end
19
+ end
20
+
21
+ describe "log files" do
22
+ it "grabs logs by default" do
23
+ expect(Cornucopia::Util::Configuration.grab_logs).to be_truthy
24
+ end
25
+
26
+ it "can set the seed value" do
27
+ begin
28
+ Cornucopia::Util::Configuration.grab_logs = false
29
+
30
+ expect(Cornucopia::Util::Configuration.grab_logs).to be_falsey
31
+ ensure
32
+ Cornucopia::Util::Configuration.grab_logs = true
33
+ end
34
+ end
35
+
36
+ it "has no custom files by default" do
37
+ expect(Cornucopia::Util::Configuration.user_log_files).to be == {}
38
+ end
39
+
40
+ it "can add custom user log files" do
41
+ begin
42
+ num_lines = rand(0..500)
43
+ some_config = Faker::Lorem.sentence
44
+
45
+ Cornucopia::Util::Configuration.add_log_file("test_log_file.log", { num_lines: num_lines, some_config: some_config })
46
+
47
+ expect(Cornucopia::Util::Configuration.user_log_files).to be == {
48
+ "test_log_file.log" => { num_lines: num_lines, some_config: some_config }
49
+ }
50
+ ensure
51
+ Cornucopia::Util::Configuration.remove_log_file("test_log_file.log")
52
+ end
53
+ end
54
+
55
+ it "can remove custom user log files" do
56
+ begin
57
+ num_lines = rand(0..500)
58
+ some_config = Faker::Lorem.sentence
59
+
60
+ Cornucopia::Util::Configuration.add_log_file("test_log_file.log", { num_lines: num_lines, some_config: some_config })
61
+
62
+ expect(Cornucopia::Util::Configuration.user_log_files).to be == {
63
+ "test_log_file.log" => { num_lines: num_lines, some_config: some_config }
64
+ }
65
+
66
+ Cornucopia::Util::Configuration.remove_log_file("test_log_file.log")
67
+
68
+ expect(Cornucopia::Util::Configuration.user_log_files).to be == {}
69
+ ensure
70
+ Cornucopia::Util::Configuration.remove_log_file("test_log_file.log")
71
+ end
72
+ end
73
+
74
+ it "can change settings for custom user log files" do
75
+ begin
76
+ num_lines = rand(0..500)
77
+ some_config = Faker::Lorem.sentence
78
+
79
+ Cornucopia::Util::Configuration.add_log_file("test_log_file.log", { num_lines: num_lines, some_config: some_config })
80
+
81
+ expect(Cornucopia::Util::Configuration.user_log_files).to be == {
82
+ "test_log_file.log" => { num_lines: num_lines, some_config: some_config }
83
+ }
84
+
85
+ num_lines = rand(501..1_000)
86
+
87
+ Cornucopia::Util::Configuration.add_log_file("test_log_file.log", { num_lines: num_lines })
88
+
89
+ expect(Cornucopia::Util::Configuration.user_log_files).to be == {
90
+ "test_log_file.log" => { num_lines: num_lines, some_config: some_config }
91
+ }
92
+ ensure
93
+ Cornucopia::Util::Configuration.remove_log_file("test_log_file.log")
94
+ end
95
+ end
96
+
97
+ describe "#num_lines" do
98
+ it "returns the default number of lines to fetch" do
99
+ expect(Cornucopia::Util::Configuration.num_lines).to be == 500
100
+ end
101
+
102
+ it "returns the default number of lines to fetch it it isn't set for a fake file" do
103
+ expect(Cornucopia::Util::Configuration.num_lines("fake_file.log")).to be == 500
104
+ end
105
+
106
+ it "returns the default number of lines to fetch it it isn't set for a file" do
107
+ begin
108
+ Cornucopia::Util::Configuration.add_log_file("test_log_file.log", { some_config: "nothing" })
109
+
110
+ expect(Cornucopia::Util::Configuration.num_lines("test_log_file.log")).to be == 500
111
+ ensure
112
+ Cornucopia::Util::Configuration.remove_log_file("test_log_file.log")
113
+ end
114
+ end
115
+
116
+ it "returns the number of lines for a specific file" do
117
+ begin
118
+ num_lines = rand(0..500)
119
+ some_config = Faker::Lorem.sentence
120
+
121
+ Cornucopia::Util::Configuration.add_log_file("test_log_file.log", { num_lines: num_lines, some_config: some_config })
122
+
123
+ expect(Cornucopia::Util::Configuration.num_lines("test_log_file.log")).to be == num_lines
124
+ ensure
125
+ Cornucopia::Util::Configuration.remove_log_file("test_log_file.log")
126
+ end
127
+ end
128
+
129
+ it "can change the defualt number of lines" do
130
+ begin
131
+ new_default = rand(0..10_000_000)
132
+
133
+ Cornucopia::Util::Configuration.default_num_lines = new_default
134
+
135
+ expect(Cornucopia::Util::Configuration.num_lines).to be == new_default
136
+ expect(Cornucopia::Util::Configuration.num_lines("fake_file.log")).to be == new_default
137
+ ensure
138
+ Cornucopia::Util::Configuration.default_num_lines = 500
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ describe "configured_reports" do
145
+ [:rspec, :cucumber, :spinach, :capybara_page_diagnostics].each do |report_type|
146
+ it "has a #{report_type} report" do
147
+ expect(Cornucopia::Util::Configuration.report_configuration(report_type)).to be
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "#print_timeout_min" do
153
+ it "#can read the default" do
154
+ expect(Cornucopia::Util::Configuration.print_timeout_min).to be == 10
155
+ end
156
+
157
+ it "#can set the value" do
158
+ begin
159
+ rand_value = rand(20..100)
160
+ Cornucopia::Util::Configuration.print_timeout_min = rand_value
161
+
162
+ expect(Cornucopia::Util::Configuration.print_timeout_min).to be == rand_value
163
+ ensure
164
+ Cornucopia::Util::Configuration.print_timeout_min = 10
165
+ end
166
+ end
167
+ end
168
+
169
+ describe "#selenium_cache_retry_count" do
170
+ it "#can read the default" do
171
+ expect(Cornucopia::Util::Configuration.selenium_cache_retry_count).to be == 5
172
+ end
173
+
174
+ it "#can set the value" do
175
+ begin
176
+ rand_value = rand(20..100)
177
+ Cornucopia::Util::Configuration.selenium_cache_retry_count = rand_value
178
+
179
+ expect(Cornucopia::Util::Configuration.selenium_cache_retry_count).to be == rand_value
180
+ ensure
181
+ Cornucopia::Util::Configuration.selenium_cache_retry_count = 5
182
+ end
183
+ end
184
+ end
185
+
186
+ describe "#analyze_find_exceptions" do
187
+ it "#can read the default" do
188
+ expect(Cornucopia::Util::Configuration.analyze_find_exceptions).to be_truthy
189
+ end
190
+
191
+ it "#can set the value" do
192
+ begin
193
+ Cornucopia::Util::Configuration.analyze_find_exceptions = false
194
+
195
+ expect(Cornucopia::Util::Configuration.analyze_find_exceptions).to be_falsy
196
+ ensure
197
+ Cornucopia::Util::Configuration.analyze_find_exceptions = true
198
+ end
199
+ end
200
+ end
201
+
202
+ describe "#retry_with_found" do
203
+ it "#can read the default" do
204
+ expect(Cornucopia::Util::Configuration.retry_with_found).to be_falsy
205
+ end
206
+
207
+ it "#can set the value" do
208
+ begin
209
+ Cornucopia::Util::Configuration.retry_with_found = true
210
+
211
+ expect(Cornucopia::Util::Configuration.retry_with_found).to be_truthy
212
+ ensure
213
+ Cornucopia::Util::Configuration.retry_with_found = false
214
+ end
215
+ end
216
+ end
217
+
218
+ describe "#auto_open_report_after_generation" do
219
+ after(:each) do
220
+ Cornucopia::Util::Configuration.class_variable_get(:@@configurations).open_report_settings = { default: false }
221
+ end
222
+
223
+ it "sets the default value if unspecified" do
224
+ Cornucopia::Util::Configuration.auto_open_report_after_generation(true)
225
+ expect(Cornucopia::Util::Configuration.class_variable_get(:@@configurations).open_report_settings)
226
+ .to eq({ default: true })
227
+ end
228
+
229
+ it "sets the value of a specific report" do
230
+ Cornucopia::Util::Configuration.auto_open_report_after_generation(true, "fred")
231
+ expect(Cornucopia::Util::Configuration.class_variable_get(:@@configurations).open_report_settings).
232
+ to eq({ default: false, "fred" => true })
233
+ end
234
+ end
235
+
236
+ describe "#open_report_after_generation" do
237
+ end
238
+
239
+ # describe "#alternate_retry" do
240
+ # it "#can read the default" do
241
+ # expect(Cornucopia::Util::Configuration.alternate_retry).to be_falsy
242
+ # end
243
+ #
244
+ # it "#can set the value" do
245
+ # begin
246
+ # Cornucopia::Util::Configuration.alternate_retry = true
247
+ #
248
+ # expect(Cornucopia::Util::Configuration.alternate_retry).to be_truthy
249
+ # ensure
250
+ # Cornucopia::Util::Configuration.alternate_retry = false
251
+ # end
252
+ # end
253
+ # end
254
+ end