cornucopia 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +51 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +16 -0
- data/LICENSE.TXT +22 -0
- data/README.md +341 -0
- data/Rakefile +18 -0
- data/cornucopia.gemspec +39 -0
- data/lib/cornucopia.rb +18 -0
- data/lib/cornucopia/capybara/finder_diagnostics.rb +536 -0
- data/lib/cornucopia/capybara/finder_extensions.rb +89 -0
- data/lib/cornucopia/capybara/install_finder_extensions.rb +105 -0
- data/lib/cornucopia/capybara/install_matcher_extensions.rb +39 -0
- data/lib/cornucopia/capybara/matcher_extensions.rb +83 -0
- data/lib/cornucopia/capybara/page_diagnostics.rb +228 -0
- data/lib/cornucopia/cucumber_hooks.rb +38 -0
- data/lib/cornucopia/factory_girl/dynamic_association.rb +14 -0
- data/lib/cornucopia/rspec_hooks.rb +37 -0
- data/lib/cornucopia/site_prism/element_extensions.rb +273 -0
- data/lib/cornucopia/site_prism/install_element_extensions.rb +23 -0
- data/lib/cornucopia/site_prism/page_application.rb +126 -0
- data/lib/cornucopia/source_files/collapse.gif +0 -0
- data/lib/cornucopia/source_files/cornucopia.css +162 -0
- data/lib/cornucopia/source_files/expand.gif +0 -0
- data/lib/cornucopia/source_files/index_base.html +10 -0
- data/lib/cornucopia/source_files/index_contents.html +2 -0
- data/lib/cornucopia/source_files/more_info.js +87 -0
- data/lib/cornucopia/source_files/report_base.html +10 -0
- data/lib/cornucopia/source_files/report_contents.html +3 -0
- data/lib/cornucopia/spinach_hooks.rb +51 -0
- data/lib/cornucopia/util/configuration.rb +493 -0
- data/lib/cornucopia/util/configured_report.rb +520 -0
- data/lib/cornucopia/util/file_asset.rb +46 -0
- data/lib/cornucopia/util/generic_settings.rb +37 -0
- data/lib/cornucopia/util/log_capture.rb +97 -0
- data/lib/cornucopia/util/pretty_formatter.rb +580 -0
- data/lib/cornucopia/util/report_builder.rb +474 -0
- data/lib/cornucopia/util/report_formatters.rb +11 -0
- data/lib/cornucopia/util/report_table.rb +195 -0
- data/lib/cornucopia/version.rb +3 -0
- data/lib/tasks/cornucopia_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +27 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cucumber.yml +8 -0
- data/spec/dummy/config/database.yml +37 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/features/support/env.rb +66 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/cucumber.rake +65 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/cucumber +10 -0
- data/spec/fixtures/sample_page.html +150 -0
- data/spec/lib/capybara/finder_diagnostics_spec.rb +517 -0
- data/spec/lib/capybara/finder_extensions_spec.rb +328 -0
- data/spec/lib/capybara/page_diagnostics_spec.rb +277 -0
- data/spec/lib/site_prism/element_extensions_spec.rb +290 -0
- data/spec/lib/site_prism/page_application_spec.rb +81 -0
- data/spec/lib/util/configuration_spec.rb +254 -0
- data/spec/lib/util/configured_report_spec.rb +1058 -0
- data/spec/lib/util/file_asset_spec.rb +86 -0
- data/spec/lib/util/generic_settings_spec.rb +48 -0
- data/spec/lib/util/log_capture_spec.rb +151 -0
- data/spec/lib/util/pretty_formatter_spec.rb +694 -0
- data/spec/lib/util/report_builder_spec.rb +983 -0
- data/spec/lib/util/report_formatters_spec.rb +13 -0
- data/spec/lib/util/report_table_exception_spec.rb +21 -0
- data/spec/lib/util/report_table_spec.rb +319 -0
- data/spec/pages/cornucopia_report_app.rb +10 -0
- data/spec/pages/google/email_page.rb +22 -0
- data/spec/pages/google/login_page.rb +25 -0
- data/spec/rails_helper.rb +43 -0
- data/spec/sample_report.rb +45 -0
- data/spec/spec_helper.rb +81 -0
- metadata +410 -0
@@ -0,0 +1,86 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "tempfile"
|
3
|
+
require ::File.expand_path("../../../lib/cornucopia/util/file_asset", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
describe Cornucopia::Util::FileAsset do
|
6
|
+
let(:asset) { Cornucopia::Util::FileAsset.new("index_contents.html") }
|
7
|
+
|
8
|
+
around(:each) do |example|
|
9
|
+
begin
|
10
|
+
FileUtils.mkdir_p(File.join(File.dirname(__FILE__), "test_file_output"))
|
11
|
+
|
12
|
+
example.run
|
13
|
+
ensure
|
14
|
+
FileUtils.rm_rf(File.join(File.dirname(__FILE__), "test_file_output"))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns the path to the default asset path" do
|
19
|
+
expect(asset.path).to be == File.absolute_path(File.join(File.dirname(__FILE__), "../../../lib/cornucopia/source_files/index_contents.html"))
|
20
|
+
end
|
21
|
+
|
22
|
+
it "copies base files" do
|
23
|
+
asset.create_file(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
24
|
+
|
25
|
+
copy_file = File.read(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
26
|
+
source_file = File.read(asset.path)
|
27
|
+
|
28
|
+
expect(copy_file).to be == source_file
|
29
|
+
end
|
30
|
+
|
31
|
+
it "allows for an overridden file asset" do
|
32
|
+
asset.body = "This is a specialized asset"
|
33
|
+
|
34
|
+
asset.create_file(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
35
|
+
|
36
|
+
copy_file = File.read(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
37
|
+
|
38
|
+
expect(copy_file).to be == "This is a specialized asset"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "allows a separate file source" do
|
42
|
+
alt_asset = Cornucopia::Util::FileAsset.new("report_base.html")
|
43
|
+
|
44
|
+
asset.source_file = alt_asset.path
|
45
|
+
|
46
|
+
asset.create_file(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
47
|
+
|
48
|
+
copy_file = File.read(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
49
|
+
source_file = File.read(alt_asset.path)
|
50
|
+
|
51
|
+
expect(copy_file).to be == source_file
|
52
|
+
end
|
53
|
+
|
54
|
+
it "adds files if they don't exist" do
|
55
|
+
asset.add_file(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
56
|
+
|
57
|
+
copy_file = File.read(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
58
|
+
source_file = File.read(asset.path)
|
59
|
+
|
60
|
+
expect(copy_file).to be == source_file
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not add a file if it already exists" do
|
64
|
+
alt_asset = Cornucopia::Util::FileAsset.new("report_base.html")
|
65
|
+
|
66
|
+
alt_asset.add_file(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
67
|
+
asset.add_file(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
68
|
+
|
69
|
+
copy_file = File.read(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
70
|
+
source_file = File.read(alt_asset.path)
|
71
|
+
|
72
|
+
expect(copy_file).to be == source_file
|
73
|
+
end
|
74
|
+
|
75
|
+
it "shares and caches file assets" do
|
76
|
+
cached = Cornucopia::Util::FileAsset.asset("index_contents.html")
|
77
|
+
cached.body = "This is a specialized asset"
|
78
|
+
|
79
|
+
alt_cached = Cornucopia::Util::FileAsset.asset("index_contents.html")
|
80
|
+
|
81
|
+
alt_cached.add_file(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
82
|
+
copy_file = File.read(File.join(File.dirname(__FILE__), "test_file_output/copy_file_test.html"))
|
83
|
+
|
84
|
+
expect(copy_file).to be == "This is a specialized asset"
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require ::File.expand_path("../../../lib/cornucopia/util/generic_settings", File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe Cornucopia::Util::GenericSettings do
|
5
|
+
let(:subject) { Cornucopia::Util::GenericSettings.new }
|
6
|
+
|
7
|
+
class Object
|
8
|
+
def method_missing(method_sym, *arguments, &block)
|
9
|
+
if method_sym == :___stupid_missing_message
|
10
|
+
"Missing message"
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def respond_to?(method_sym, include_private = false)
|
17
|
+
if method_sym == :___stupid_missing_message
|
18
|
+
true
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "responds_to? anything" do
|
26
|
+
expect(subject.respond_to?(Faker::Lorem.word)).to be_truthy
|
27
|
+
end
|
28
|
+
|
29
|
+
it "calls the super implementation of somthing if it exists" do
|
30
|
+
expect(subject.object_id).to be
|
31
|
+
end
|
32
|
+
|
33
|
+
it "looks for a value in a hash if it isn't recognized" do
|
34
|
+
expect(subject.send(Faker::Lorem.word)).not_to be
|
35
|
+
end
|
36
|
+
|
37
|
+
it "will store a value in anything that isn't a base function" do
|
38
|
+
stored_value = Faker::Lorem.paragraphs
|
39
|
+
value_name = Faker::Lorem.word
|
40
|
+
|
41
|
+
subject.send("#{value_name}=", stored_value)
|
42
|
+
expect(subject.send(value_name)).to be == stored_value
|
43
|
+
end
|
44
|
+
|
45
|
+
it "calls the super method" do
|
46
|
+
expect(subject.___stupid_missing_message).to be == "Missing message"
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require ::File.expand_path("../../../lib/cornucopia/util/log_capture", File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe Cornucopia::Util::LogCapture do
|
5
|
+
let(:file_name) { Rails.root.join("sample_log.log") }
|
6
|
+
|
7
|
+
around(:each) do |example|
|
8
|
+
expect(File.directory?(Rails.root.join("cornucopia_report/"))).to be_falsey
|
9
|
+
expect(File.directory?(Rails.root.join("spec/cornucopia_report/"))).to be_falsey
|
10
|
+
expect(File.directory?(Rails.root.join("features/cornucopia_report/"))).to be_falsey
|
11
|
+
expect(File.exists?(file_name)).to be_falsey
|
12
|
+
|
13
|
+
begin
|
14
|
+
example.run
|
15
|
+
ensure
|
16
|
+
if (Cornucopia::Util::ReportBuilder.class_variable_get("@@current_report"))
|
17
|
+
Cornucopia::Util::ReportBuilder.current_report.close
|
18
|
+
end
|
19
|
+
|
20
|
+
FileUtils.rm_rf Rails.root.join("cornucopia_report/")
|
21
|
+
FileUtils.rm_rf Rails.root.join("spec/cornucopia_report/")
|
22
|
+
FileUtils.rm_rf Rails.root.join("features/cornucopia_report/")
|
23
|
+
FileUtils.rm_rf Rails.root.join("features") if Dir[Rails.root.join("features/*")].empty?
|
24
|
+
FileUtils.rm_rf file_name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#highlight_log_output" do
|
29
|
+
it "should color error lines" do
|
30
|
+
error_line = Cornucopia::Util::LogCapture.highlight_log_output("Completed 404 this is an error")
|
31
|
+
expect(error_line).to be_html_safe
|
32
|
+
expect(error_line).to match(/\>Completed 404 this is an error\</)
|
33
|
+
expect(error_line).to match(/^\<span/)
|
34
|
+
expect(error_line).to match(/\<\/span\>$/)
|
35
|
+
expect(error_line).to match(/completed-error/)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should color success lines" do
|
39
|
+
error_line = Cornucopia::Util::LogCapture.highlight_log_output("Completed 302 this is a redirect")
|
40
|
+
expect(error_line).to be_html_safe
|
41
|
+
expect(error_line).to match(/\>Completed 302 this is a redirect\</)
|
42
|
+
expect(error_line).to match(/^\<span/)
|
43
|
+
expect(error_line).to match(/\<\/span\>$/)
|
44
|
+
expect(error_line).to match(/completed-other/)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should color both error and success lines" do
|
48
|
+
error_line = Cornucopia::Util::LogCapture.highlight_log_output("Completed 404 this is an error\nCompleted 302 this is a redirect")
|
49
|
+
expect(error_line).to be_html_safe
|
50
|
+
expect(error_line).to match(/\>Completed 404 this is an error\</)
|
51
|
+
expect(error_line).to match(/^\<span/)
|
52
|
+
expect(error_line).to match(/\<\/span\>$/)
|
53
|
+
expect(error_line).to match(/completed-error/)
|
54
|
+
expect(error_line).to match(/\>Completed 302 this is a redirect\</)
|
55
|
+
expect(error_line).to match(/^\<span/)
|
56
|
+
expect(error_line).to match(/\<\/span\>$/)
|
57
|
+
expect(error_line).to match(/completed-other/)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#output_log_file" do
|
62
|
+
it "fetches the last 500 lines of a file" do
|
63
|
+
lines = Faker::Lorem.sentences(rand(600..1000))
|
64
|
+
File.open(file_name, "a:UTF-8") do |write_file|
|
65
|
+
write_file.write(lines.join("\n"))
|
66
|
+
end
|
67
|
+
|
68
|
+
report_table = Cornucopia::Util::ReportTable.new do |table|
|
69
|
+
Cornucopia::Util::LogCapture.output_log_file(table, file_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
expect(report_table.full_table).to match /#{lines[-500..-1].join("\n")}/
|
73
|
+
expect(report_table.full_table).to_not match /#{lines[-501..-1].join("\n")}/
|
74
|
+
end
|
75
|
+
|
76
|
+
it "fetches the last 500 lines of a file even if it has to fetch multiple times" do
|
77
|
+
lines = (0..rand(600..1000)).to_a.map { Faker::Lorem.sentences(rand(5..10)).join(" ") }
|
78
|
+
File.open(file_name, "a:UTF-8") do |write_file|
|
79
|
+
write_file.write(lines.join("\n"))
|
80
|
+
end
|
81
|
+
|
82
|
+
report_table = Cornucopia::Util::ReportTable.new do |table|
|
83
|
+
Cornucopia::Util::LogCapture.output_log_file(table, file_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
expect(report_table.full_table).to match /#{lines[-500..-1].join("\n")}/
|
87
|
+
expect(report_table.full_table).to_not match /#{lines[-501..-1].join("\n")}/
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#capture_logs" do
|
92
|
+
after(:each) do
|
93
|
+
Cornucopia::Util::Configuration.remove_log_file("sample_log.log")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "starts a new report if it is not passed a table" do
|
97
|
+
expect(Cornucopia::Util::ReportBuilder).to receive(:current_report).and_call_original
|
98
|
+
expect(Cornucopia::Util::LogCapture).to receive(:capture_logs).twice.and_call_original
|
99
|
+
Cornucopia::Util::Configuration.add_log_file("sample_log.log")
|
100
|
+
|
101
|
+
lines = Faker::Lorem.sentences(rand(600..1000))
|
102
|
+
File.open(file_name, "a:UTF-8") do |write_file|
|
103
|
+
write_file.write(lines.join("\n"))
|
104
|
+
end
|
105
|
+
|
106
|
+
Cornucopia::Util::LogCapture.capture_logs(nil)
|
107
|
+
|
108
|
+
report_data = File.read(Rails.root.join("cornucopia_report/cornucopia_report/report_contents.html"))
|
109
|
+
expect(report_data).to match /#{lines[-500..-1].join("\n")}/
|
110
|
+
expect(report_data).to_not match /#{lines[-501..-1].join("\n")}/
|
111
|
+
end
|
112
|
+
|
113
|
+
it "goes up one level if you are in spec or features" do
|
114
|
+
expect(Cornucopia::Util::ReportBuilder).to receive(:current_report).and_call_original
|
115
|
+
expect(Cornucopia::Util::LogCapture).to receive(:capture_logs).twice.and_call_original
|
116
|
+
Cornucopia::Util::Configuration.add_log_file("sample_log.log")
|
117
|
+
|
118
|
+
lines = Faker::Lorem.sentences(rand(600..1000))
|
119
|
+
File.open(file_name, "a:UTF-8") do |write_file|
|
120
|
+
write_file.write(lines.join("\n"))
|
121
|
+
end
|
122
|
+
|
123
|
+
new_root = Rails.root.join(%w(features features).sample).to_s
|
124
|
+
expect(Rails).to receive(:root).at_least(1).and_return(new_root)
|
125
|
+
Cornucopia::Util::LogCapture.capture_logs(nil)
|
126
|
+
|
127
|
+
report_data = File.read(File.join(new_root, "cornucopia_report/cornucopia_report/report_contents.html"))
|
128
|
+
expect(report_data).to match /#{lines[-500..-1].join("\n")}/
|
129
|
+
expect(report_data).to_not match /#{lines[-501..-1].join("\n")}/
|
130
|
+
end
|
131
|
+
|
132
|
+
it "does not require Rails" do
|
133
|
+
expect(Cornucopia::Util::ReportBuilder).to receive(:current_report).and_call_original
|
134
|
+
expect(Cornucopia::Util::LogCapture).to receive(:capture_logs).twice.and_call_original
|
135
|
+
Cornucopia::Util::Configuration.add_log_file("sample_log.log")
|
136
|
+
FileUtils.cd Rails.root.to_s
|
137
|
+
expect(Object).to receive(:const_defined?).at_least(1).with("Rails").and_return(false)
|
138
|
+
|
139
|
+
lines = Faker::Lorem.sentences(rand(600..1000))
|
140
|
+
File.open(file_name, "a:UTF-8") do |write_file|
|
141
|
+
write_file.write(lines.join("\n"))
|
142
|
+
end
|
143
|
+
|
144
|
+
Cornucopia::Util::LogCapture.capture_logs(nil)
|
145
|
+
|
146
|
+
report_data = File.read(Rails.root.join("cornucopia_report/cornucopia_report/report_contents.html"))
|
147
|
+
expect(report_data).to match /#{lines[-500..-1].join("\n")}/
|
148
|
+
expect(report_data).to_not match /#{lines[-501..-1].join("\n")}/
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,694 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require ::File.expand_path("../../../lib/cornucopia/util/pretty_formatter", File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe Cornucopia::Util::PrettyFormatter do
|
5
|
+
let(:formatted_string) { "#<AClass\nmy_variable = \"a value \",\n \"another\"=0>" }
|
6
|
+
let(:simple_class) { "#<AClass>" }
|
7
|
+
let(:simple_variable) { "#<AClass \"variable\"=\"value\", something = something else>" }
|
8
|
+
let(:simple_variable_expectations) { "#<AClass\n \"variable\" = \"value\",\n something = something else\n>" }
|
9
|
+
let(:simple_array) { "#<AClass \"array\" = [[a,b,c],\"value\", something here, \"\\\"some\\\\thing\\\"\", a_value]>" }
|
10
|
+
let(:simple_array_expectations) { "#<AClass\n \"array\" =\n [\n [\n a,\n b,\n c\n ],\n \"value\",\n something here,\n \"\\\"some\\\\thing\\\"\",\n a_value\n ]\n>" }
|
11
|
+
let(:simple_hash) { "#<AClass \"hash\" = {:value => something here, \"\\\"some\\\\thing\\\"\" => a value, symbol: :symbol_also } >" }
|
12
|
+
let(:simple_hash_expectations) { "#<AClass\n \"hash\" =\n {\n :value => something here,\n \"\\\"some\\\\thing\\\"\" => a value,\n symbol: :symbol_also\n }\n>" }
|
13
|
+
|
14
|
+
it "doesn't format a formatted string" do
|
15
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(formatted_string)
|
16
|
+
expect(pretty).to be == formatted_string
|
17
|
+
|
18
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(formatted_string.gsub(/\n/, " "))
|
19
|
+
expect(pretty).to_not be == formatted_string
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "bad states" do
|
23
|
+
["\"", "{", "["].each do |test_char|
|
24
|
+
it "gives up if it finds bad characters = #{test_char}" do
|
25
|
+
test_string = "#<ACl#{test_char}ass \"variable\"=\"value\", something = something else>"
|
26
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_string)
|
27
|
+
expect(pretty).to be == "\n#{test_string}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "knows what to do with a comma" do
|
32
|
+
test_string = "#<AClass \"variable\", something = , something else>"
|
33
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_string)
|
34
|
+
expect(pretty).to be == "#<AClass\n \"variable\" ,something =,\n something \nelse>"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "knows what to do with a comma after a =>" do
|
38
|
+
test_string = "#<AClass \"variable\" = { :hash =>,>"
|
39
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_string)
|
40
|
+
expect(pretty).to be == "#<AClass\n \"variable\" =\n {\n :hash => ,\n>"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "knows what to do with a comma instead of a =>" do
|
44
|
+
test_string = "#<AClass \"variable\" = { :hash,>"
|
45
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_string)
|
46
|
+
expect(pretty).to be == "#<AClass\n \"variable\" =\n {\n :hash , \n>"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is a test" do
|
50
|
+
test_string = "#<AClass hash: value>"
|
51
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_string)
|
52
|
+
expect(pretty).to be == "#<AClass\n hash: value\n>"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "breaks if a hash is invalid" do
|
56
|
+
test_string = "#<AClass {\"variable\" = >,}>"
|
57
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_string)
|
58
|
+
expect(pretty).to be == "#<AClass\n {\n \"variable\" \n= >,}>"
|
59
|
+
|
60
|
+
test_string = "#<AClass {\"variable\" => \"VALUE\" t}>"
|
61
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_string)
|
62
|
+
expect(pretty).to be == "#<AClass\n {\n \"variable\" => \"VALUE\"\nt}>"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "formats a simple class" do
|
67
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(simple_class)
|
68
|
+
expect(pretty).to be == simple_class
|
69
|
+
end
|
70
|
+
|
71
|
+
it "formats a simple variable" do
|
72
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(simple_variable)
|
73
|
+
expect(pretty).to be == simple_variable_expectations
|
74
|
+
end
|
75
|
+
|
76
|
+
it "formats a simple class in bigger text" do
|
77
|
+
pre_text = rand(0..1) == 0 ? "#{Faker::Lorem.sentence}\n" : ""
|
78
|
+
post_text = rand(0..1) == 0 ? "\n#{Faker::Lorem.sentence}" : ""
|
79
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string("#{pre_text[0..-2]}#{simple_variable}#{post_text[1..-1]}")
|
80
|
+
|
81
|
+
expect(pretty).to be == expectation_in_text(simple_variable_expectations, pre_text, post_text)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "formats an array" do
|
85
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(simple_array)
|
86
|
+
expect(pretty).to be == simple_array_expectations
|
87
|
+
end
|
88
|
+
|
89
|
+
it "formats a simple array in bigger text" do
|
90
|
+
pre_text = rand(0..1) == 0 ? "#{Faker::Lorem.sentence}\n" : ""
|
91
|
+
post_text = rand(0..1) == 0 ? "\n#{Faker::Lorem.sentence}" : ""
|
92
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string("#{pre_text[0..-2]}#{simple_array}#{post_text[1..-1]}")
|
93
|
+
|
94
|
+
expect(pretty).to be == expectation_in_text(simple_array_expectations, pre_text, post_text)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "formats an hash" do
|
98
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(simple_hash)
|
99
|
+
expect(pretty).to be == simple_hash_expectations
|
100
|
+
end
|
101
|
+
|
102
|
+
it "formats a simple hash in bigger text" do
|
103
|
+
pre_text = rand(0..1) == 0 ? "#{Faker::Lorem.sentence}\n" : ""
|
104
|
+
post_text = rand(0..1) == 0 ? "\n#{Faker::Lorem.sentence}" : ""
|
105
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string("#{pre_text[0..-2]}#{simple_hash}#{post_text[1..-1]}")
|
106
|
+
|
107
|
+
expect(pretty).to be == expectation_in_text(simple_hash_expectations, pre_text, post_text)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "formats a known problem string 1" do
|
111
|
+
format_value = "#<class @silencers=#<class @silencers=[#<Proc:0x007f8d9f2a15f0@/Users/elittell/.rvm/gems/ruby-1.9.3-p327@homerun/gems/railties-3.2.13/lib/rails/backtrace_cleaner.rb:15>]>, \"HTTP_HO\"=\"HTTP_HO\">"
|
112
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
113
|
+
|
114
|
+
expect(pretty).to be == "#<class\n @silencers =\n #<class\n @silencers =\n [\n #<Proc:0x007f8d9f2a15f0@/Users/elittell/.rvm/gems/ruby-1.9.3-p327@homerun/gems/railties-3.2.13/lib/rails/backtrace_cleaner.rb:15>\n ]\n >,\n \"HTTP_HO\" = \"HTTP_HO\"\n>"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "formats an implied hash" do
|
118
|
+
format_value = "#<DbInjector::Deal id: 1, slug: \"6ff445f3\", type: \"daily-deal\">"
|
119
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
120
|
+
|
121
|
+
expect(pretty).to be == "#<DbInjector::Deal\n id: 1,\n slug: \"6ff445f3\",\n type: \"daily-deal\"\n>"
|
122
|
+
|
123
|
+
format_value = "".html_safe + "#<DbInjector::Deal id: 1, slug: \"6ff445f3\", type: \"daily-deal\">"
|
124
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
125
|
+
|
126
|
+
expect(pretty).to be == "#<DbInjector::Deal\n id: 1,\n slug: "6ff445f3",\n type: "daily-deal"\n>"
|
127
|
+
expect(pretty).to be_html_safe
|
128
|
+
end
|
129
|
+
|
130
|
+
it "formats an implied hash" do
|
131
|
+
format_value = "#<DbInjector::Deal id: 1, slug: \"6ff445f3\", type: \"daily-deal\"> fred"
|
132
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
133
|
+
|
134
|
+
expect(pretty).to be == "#<DbInjector::Deal\n id: 1,\n slug: \"6ff445f3\",\n type: \"daily-deal\"\n>\n fred"
|
135
|
+
|
136
|
+
format_value = "".html_safe + "#<DbInjector::Deal id: 1, slug: \"6ff445f3\", type: \"daily-deal\"> fred"
|
137
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
138
|
+
|
139
|
+
expect(pretty).to be == "#<DbInjector::Deal\n id: 1,\n slug: "6ff445f3",\n type: "daily-deal"\n>\n fred"
|
140
|
+
expect(pretty).to be_html_safe
|
141
|
+
end
|
142
|
+
|
143
|
+
it "formats an implied hash with a hash-rocket" do
|
144
|
+
format_value = "#<DbInjector::Deal id => 1, slug => \"6ff445f3\", type => \"daily-deal\">"
|
145
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
146
|
+
|
147
|
+
expect(pretty).to be == "#<DbInjector::Deal\n id => 1,\n slug => \"6ff445f3\",\n type => \"daily-deal\"\n>"
|
148
|
+
|
149
|
+
format_value = "".html_safe + "#<DbInjector::Deal id => 1, slug => \"6ff445f3\", type => \"daily-deal\">"
|
150
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
151
|
+
|
152
|
+
expect(pretty).to be == "#<DbInjector::Deal\n id => 1,\n slug => "6ff445f3",\n type => "daily-deal"\n>"
|
153
|
+
expect(pretty).to be_html_safe
|
154
|
+
end
|
155
|
+
|
156
|
+
it "formats parameters" do
|
157
|
+
format_value = "Parameters: { \"id\" => \"value\", \"deal\"=>{\"affinity_score\"=>nil, \"buy_button_clicks\"=>6 }, \"custom_data\"=>{\"custom_data\"=>{}} }"
|
158
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
159
|
+
expected = "Parameters:\n {\n \"id\" => \"value\",\n \"deal\" =>\n {\n \"affinity_score\" => nil,\n \"buy_button_clicks\" => 6\n },\n \"custom_data\" =>\n {\n \"custom_data\" =>\n {\n }\n }\n }"
|
160
|
+
|
161
|
+
expect(pretty).to be == expected
|
162
|
+
|
163
|
+
format_value = "".html_safe + format_value
|
164
|
+
expected = "".html_safe + expected
|
165
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
166
|
+
|
167
|
+
expect(pretty).to be == expected
|
168
|
+
expect(pretty).to be_html_safe
|
169
|
+
end
|
170
|
+
|
171
|
+
it "formats parameters embedded in text" do
|
172
|
+
format_value = "this is some expectation_in_text Parameters: { \"id\" => \"value\", \"deal\"=>{\"affinity_score\"=>nil, \"buy_button_clicks\"=>6 }, \"custom_data\"=>{\"custom_data\"=>{}} } this is some expectation_in_text"
|
173
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
174
|
+
expected = "this is some expectation_in_text\n Parameters:\n {\n \"id\" => \"value\",\n \"deal\" =>\n {\n \"affinity_score\" => nil,\n \"buy_button_clicks\" => 6\n },\n \"custom_data\" =>\n {\n \"custom_data\" =>\n {\n }\n }\n }\n this is some expectation_in_text"
|
175
|
+
|
176
|
+
expect(pretty).to be == expected
|
177
|
+
|
178
|
+
format_value = "".html_safe + format_value
|
179
|
+
expected = "".html_safe + expected
|
180
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
181
|
+
|
182
|
+
expect(pretty).to be == expected
|
183
|
+
expect(pretty).to be_html_safe
|
184
|
+
end
|
185
|
+
|
186
|
+
it "formats multiple parameters embedded in text" do
|
187
|
+
format_value = "this is some expectation_in_text Parameters: { \"id\" => \"value\", \"deal\"=>{\"affinity_score\"=>nil, \"buy_button_clicks\"=>6 }, \"custom_data\"=>{\"custom_data\"=>{}} } this is some expectation_in_textthis is some expectation_in_text Parameters: { \"id\" => \"value\", \"deal\"=>{\"affinity_score\"=>nil, \"buy_button_clicks\"=>6 }, \"custom_data\"=>{\"custom_data\"=>{}} } this is some expectation_in_text"
|
188
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
189
|
+
expected = "this is some expectation_in_text\n Parameters:\n {\n \"id\" => \"value\",\n \"deal\" =>\n {\n \"affinity_score\" => nil,\n \"buy_button_clicks\" => 6\n },\n \"custom_data\" =>\n {\n \"custom_data\" =>\n {\n }\n }\n }\n this is some expectation_in_textthis is some expectation_in_text\n Parameters:\n {\n \"id\" => \"value\",\n \"deal\" =>\n {\n \"affinity_score\" => nil,\n \"buy_button_clicks\" => 6\n },\n \"custom_data\" =>\n {\n \"custom_data\" =>\n {\n }\n }\n }\n this is some expectation_in_text"
|
190
|
+
|
191
|
+
expect(pretty).to be == expected
|
192
|
+
|
193
|
+
format_value = "".html_safe + format_value
|
194
|
+
expected = "".html_safe + expected
|
195
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
196
|
+
|
197
|
+
expect(pretty).to be == expected
|
198
|
+
expect(pretty).to be_html_safe
|
199
|
+
end
|
200
|
+
|
201
|
+
it "formats bad parameters embedded in text" do
|
202
|
+
format_value = "[PartnerScope] Set to: chameleon_basic\nProcessing by DealsController#show as HTML\n Parameters: {\";id\"=>\"5e2a61bd\"}\nGET http://admin-homerun.localhost:3001//api/v2/deals/5e2a61bd.json?include=all"
|
203
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
204
|
+
expected = "[PartnerScope] Set to: chameleon_basic\nProcessing by DealsController#show as HTML\n Parameters:\n {\n \";id\" => \"5e2a61bd\"\n }\n\nGET http://admin-homerun.localhost:3001//api/v2/deals/5e2a61bd.json?include=all"
|
205
|
+
|
206
|
+
expect(pretty).to be == expected
|
207
|
+
|
208
|
+
format_value = ("".html_safe + format_value).to_s
|
209
|
+
expected = "".html_safe + expected
|
210
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
211
|
+
|
212
|
+
expect(pretty).to be == expected
|
213
|
+
expect(pretty).to be_html_safe
|
214
|
+
end
|
215
|
+
|
216
|
+
it "formats Parameters: {}" do
|
217
|
+
format_value = "Parameters:{}"
|
218
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
219
|
+
expected = "Parameters:\n {\n }"
|
220
|
+
|
221
|
+
expect(pretty).to be == expected
|
222
|
+
|
223
|
+
format_value = ("".html_safe + format_value).to_s
|
224
|
+
expected = "".html_safe + expected
|
225
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(format_value)
|
226
|
+
|
227
|
+
expect(pretty).to be == expected
|
228
|
+
expect(pretty).to be_html_safe
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "helpers" do
|
232
|
+
[:parameters,
|
233
|
+
:embedded_class,
|
234
|
+
:class,
|
235
|
+
:class_with_value,
|
236
|
+
:implied_hash,
|
237
|
+
:hash,
|
238
|
+
:array].each do |value_type|
|
239
|
+
it "can create a #{value_type} value" do
|
240
|
+
create_value(0, value_type)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
[:whitespace,
|
245
|
+
:value_name_simple,
|
246
|
+
:value_method,
|
247
|
+
:value_name_string,
|
248
|
+
:hash_key_string,
|
249
|
+
:value_string,
|
250
|
+
:value_name_complex_string,
|
251
|
+
:value_complex_string,
|
252
|
+
:hash_key_complex_string,
|
253
|
+
:value_simple,
|
254
|
+
:hash_key_symbol,
|
255
|
+
:hash_key_reversed_symbol
|
256
|
+
].each do |value_type|
|
257
|
+
it "can create a #{value_type} simple value" do
|
258
|
+
create_simple_value(0, value_type)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "tests" do
|
264
|
+
it "formats a complicated value" do
|
265
|
+
test_value, expected_value = create_value(0, [:class, :embedded_class, :implied_hash, :parameters].sample)
|
266
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_value)
|
267
|
+
expect(pretty).to be == expected_value
|
268
|
+
end
|
269
|
+
|
270
|
+
it "formats an html_safe complicated value" do
|
271
|
+
test_value, expected_value = create_value(0, [:class, :embedded_class, :implied_hash, :parameters].sample)
|
272
|
+
test_value = "".html_safe + test_value
|
273
|
+
expected_value = "".html_safe + expected_value
|
274
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_value)
|
275
|
+
expect(pretty).to be == expected_value
|
276
|
+
expect(pretty).to be_html_safe
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
# (1..100).to_a.each do |index|
|
281
|
+
(1..10).to_a.each do |index|
|
282
|
+
it "formats a complicated value (#{index})" do
|
283
|
+
test_value, expected_value = create_value(0, [:class, :embedded_class, :implied_hash, :parameters].sample)
|
284
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_value)
|
285
|
+
expect(pretty).to be == expected_value
|
286
|
+
end
|
287
|
+
|
288
|
+
it "formats an html_safe complicated value (#{index})" do
|
289
|
+
test_value, expected_value = create_value(0, [:class, :embedded_class, :implied_hash, :parameters].sample)
|
290
|
+
test_value = "".html_safe + test_value
|
291
|
+
expected_value = "".html_safe + expected_value
|
292
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string(test_value)
|
293
|
+
expect(pretty).to be == expected_value
|
294
|
+
expect(pretty).to be_html_safe
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def create_simple_value(type, options = {})
|
300
|
+
case type
|
301
|
+
when :whitespace
|
302
|
+
if rand(0..10) == 0
|
303
|
+
simple_val = ""
|
304
|
+
else
|
305
|
+
simple_val = " " * rand(1..10)
|
306
|
+
simple_val += "\t" * rand(0..10)
|
307
|
+
unless options[:spaces_only]
|
308
|
+
simple_val += "\n" * rand(0..10)
|
309
|
+
simple_val += "\r" * rand(0..10)
|
310
|
+
end
|
311
|
+
simple_val = simple_val.split("").sample(100).join("")
|
312
|
+
end
|
313
|
+
|
314
|
+
when :value_name_simple, :value_method
|
315
|
+
simple_val = Faker::Lorem.word
|
316
|
+
simple_val = "#{simple_val}?" if rand(0..1) == 0
|
317
|
+
simple_val = "@#{simple_val}" if rand(0..1) == 0
|
318
|
+
|
319
|
+
when :value_name_string, :hash_key_string, :value_string
|
320
|
+
simple_val = "\"#{Faker::Lorem.sentence}\""
|
321
|
+
|
322
|
+
when :value_name_complex_string, :value_complex_string, :hash_key_complex_string
|
323
|
+
simple_val = "'#{'{}<>[]\"\#~?/`!@#$%^&*()-_=+`'}".split("").sample(rand(5..10)).join("")
|
324
|
+
simple_val = "#{simple_val}#{Faker::Lorem.word}".split("").join("")
|
325
|
+
simple_val = "#{Faker::Lorem.sentence} #{simple_val}".split(" ").join(" ")
|
326
|
+
simple_val = simple_val.gsub(/([\\\"])/, "\\\\\\1")
|
327
|
+
simple_val = "\"#{simple_val}\""
|
328
|
+
|
329
|
+
when :value_simple
|
330
|
+
case [:number, :float, :date, :date_time, :string, :word].sample
|
331
|
+
when :number
|
332
|
+
simple_val = rand(-9999999999..9999999999)
|
333
|
+
|
334
|
+
when :float
|
335
|
+
simple_val = rand * (10 ** rand(0..15))
|
336
|
+
|
337
|
+
when :date
|
338
|
+
simple_val = Date.today + rand(-99999..99999).days
|
339
|
+
|
340
|
+
when :date_time
|
341
|
+
simple_val = DateTime.now + rand(-9999999999..9999999999).seconds
|
342
|
+
|
343
|
+
when :string
|
344
|
+
simple_val = Faker::Lorem.sentence
|
345
|
+
|
346
|
+
when :word
|
347
|
+
simple_val = Faker::Lorem.word
|
348
|
+
end
|
349
|
+
|
350
|
+
when :hash_key_symbol
|
351
|
+
simple_val = ":#{Faker::Lorem.word}"
|
352
|
+
|
353
|
+
when :hash_key_reversed_symbol
|
354
|
+
simple_val = "#{Faker::Lorem.word}:"
|
355
|
+
end
|
356
|
+
|
357
|
+
simple_val.to_s
|
358
|
+
end
|
359
|
+
|
360
|
+
def create_value(level, type, options = {})
|
361
|
+
case type
|
362
|
+
when :parameters
|
363
|
+
sub_options = options.merge({ spaces_only: true })
|
364
|
+
|
365
|
+
pre_value = rand(0..1) == 0 ? Faker::Lorem.sentence : ""
|
366
|
+
post_value = rand(0..1) == 0 ? Faker::Lorem.sentence : ""
|
367
|
+
|
368
|
+
unless pre_value.blank?
|
369
|
+
if rand(0..1) == 0
|
370
|
+
pre_value << create_simple_value(:whitespace, options)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
unless post_value.blank?
|
375
|
+
if rand(0..1) == 0
|
376
|
+
post_value = "#{create_simple_value(:whitespace, options)}#{post_value}"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
if pre_value.blank?
|
381
|
+
val, expected = create_value(level + 1, :hash, sub_options)
|
382
|
+
else
|
383
|
+
val, expected = create_value(level + 2, :hash, sub_options)
|
384
|
+
end
|
385
|
+
unless post_value.blank?
|
386
|
+
post_value = "\n#{post_value}"
|
387
|
+
end
|
388
|
+
|
389
|
+
value_val = "#{pre_value}Parameters:#{create_simple_value(:whitespace, sub_options)}#{val}#{post_value}"
|
390
|
+
value_expect = "#{pre_value.rstrip}#{pre_value.rstrip.blank? ? "" : "\n "}Parameters:\n#{expected}\n#{post_value.rstrip}"
|
391
|
+
|
392
|
+
rand(0..5).times do
|
393
|
+
pre_value = rand(0..1) == 0 ? Faker::Lorem.sentence : ""
|
394
|
+
post_value = rand(0..1) == 0 ? Faker::Lorem.sentence : ""
|
395
|
+
|
396
|
+
if rand(0..1) == 0
|
397
|
+
val = create_simple_value(:whitespace, options)
|
398
|
+
value_val << val
|
399
|
+
value_expect << val
|
400
|
+
end
|
401
|
+
|
402
|
+
if rand(0..1) == 0
|
403
|
+
val = Faker::Lorem.sentence
|
404
|
+
value_val << val
|
405
|
+
value_expect << val
|
406
|
+
|
407
|
+
if rand(0..1) == 0
|
408
|
+
val = create_simple_value(:whitespace, options)
|
409
|
+
value_val << val
|
410
|
+
value_expect << val
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
if pre_value.blank?
|
415
|
+
if rand(0..1) == 0
|
416
|
+
pre_value << create_simple_value(:whitespace, options)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
unless post_value.blank?
|
421
|
+
if rand(0..1) == 0
|
422
|
+
post_value = "#{create_simple_value(:whitespace, options)}#{post_value}"
|
423
|
+
end
|
424
|
+
end
|
425
|
+
unless post_value.blank?
|
426
|
+
post_value = "\n#{post_value}"
|
427
|
+
end
|
428
|
+
if pre_value.rstrip.blank?
|
429
|
+
value_expect.rstrip!
|
430
|
+
end
|
431
|
+
|
432
|
+
val, expected = create_value(level + 2, :hash, sub_options)
|
433
|
+
|
434
|
+
value_val << "#{pre_value}Parameters:#{create_simple_value(:whitespace, sub_options)}#{val}#{post_value}"
|
435
|
+
value_expect << "#{pre_value.rstrip}\n Parameters:\n#{expected}\n#{post_value.rstrip}"
|
436
|
+
end
|
437
|
+
|
438
|
+
value_expect.rstrip!
|
439
|
+
|
440
|
+
when :embedded_class
|
441
|
+
pre_value = rand(0..1) == 0 ? Faker::Lorem.sentence : ""
|
442
|
+
post_value = rand(0..1) == 0 ? Faker::Lorem.sentence : ""
|
443
|
+
|
444
|
+
unless pre_value.blank?
|
445
|
+
if rand(0..1) == 0
|
446
|
+
pre_value << create_simple_value(:whitespace, options)
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
unless post_value.blank?
|
451
|
+
if rand(0..1) == 0
|
452
|
+
post_value = "#{create_simple_value(:whitespace, options)}#{post_value}"
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
if pre_value.blank?
|
457
|
+
val, expected = create_value(level, :class_with_value, options)
|
458
|
+
else
|
459
|
+
val, expected = create_value(level + 1, :class_with_value, options)
|
460
|
+
end
|
461
|
+
unless post_value.blank?
|
462
|
+
post_value = "\n#{post_value}"
|
463
|
+
end
|
464
|
+
|
465
|
+
value_val = "#{pre_value}#{val}#{post_value}"
|
466
|
+
value_expect = "#{pre_value.rstrip}#{pre_value.rstrip.blank? ? "" : "\n"}#{expected}\n#{post_value.rstrip}"
|
467
|
+
|
468
|
+
rand(0..5).times do
|
469
|
+
pre_value = rand(0..1) == 0 ? Faker::Lorem.sentence : ""
|
470
|
+
post_value = rand(0..1) == 0 ? Faker::Lorem.sentence : ""
|
471
|
+
|
472
|
+
if rand(0..1) == 0
|
473
|
+
val = create_simple_value(:whitespace, options)
|
474
|
+
value_val << val
|
475
|
+
value_expect << val
|
476
|
+
end
|
477
|
+
|
478
|
+
if rand(0..1) == 0
|
479
|
+
val = Faker::Lorem.sentence
|
480
|
+
value_val << val
|
481
|
+
value_expect << val
|
482
|
+
|
483
|
+
if rand(0..1) == 0
|
484
|
+
val = create_simple_value(:whitespace, options)
|
485
|
+
value_val << val
|
486
|
+
value_expect << val
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
if pre_value.blank?
|
491
|
+
if rand(0..1) == 0
|
492
|
+
pre_value << create_simple_value(:whitespace, options)
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
unless post_value.blank?
|
497
|
+
if rand(0..1) == 0
|
498
|
+
post_value = "#{create_simple_value(:whitespace, options)}#{post_value}"
|
499
|
+
end
|
500
|
+
end
|
501
|
+
unless post_value.blank?
|
502
|
+
post_value = "\n#{post_value}"
|
503
|
+
end
|
504
|
+
if pre_value.rstrip.blank?
|
505
|
+
value_expect.rstrip!
|
506
|
+
end
|
507
|
+
|
508
|
+
val, expected = create_value(level + 1, :class, options)
|
509
|
+
|
510
|
+
value_val << "#{pre_value}#{val}#{post_value}"
|
511
|
+
value_expect << "#{pre_value.rstrip}\n#{expected}\n#{post_value.rstrip}"
|
512
|
+
end
|
513
|
+
|
514
|
+
value_expect.rstrip!
|
515
|
+
|
516
|
+
when :class, :class_with_value
|
517
|
+
name = create_simple_value(:value_name_simple, options)
|
518
|
+
value_val = "\#<#{name}#{" " * rand(1..10)}"
|
519
|
+
value_expect = "#{" " * level}\#<#{name}"
|
520
|
+
append_value = ""
|
521
|
+
append_expect = "\n"
|
522
|
+
|
523
|
+
range_start = type == :class ? 0 : 1
|
524
|
+
|
525
|
+
rand(range_start..5).times do
|
526
|
+
name = create_simple_value([:value_name_complex_string, :value_name_simple, :value_name_string].sample, options)
|
527
|
+
val_type = [:class, :value, :hash, :array].sample
|
528
|
+
val_type = :value if level > 4 || rand(0.1) == 0
|
529
|
+
|
530
|
+
case val_type
|
531
|
+
when :class, :hash, :array
|
532
|
+
val, expected = create_value(level + 2, val_type, options)
|
533
|
+
|
534
|
+
when :value
|
535
|
+
val = create_simple_value([:value_simple, :value_string, :value_method, :value_complex_string].sample, options)
|
536
|
+
expected = val
|
537
|
+
end
|
538
|
+
|
539
|
+
value_val << "#{append_value}#{name}#{create_simple_value(:whitespace, options)}=#{create_simple_value(:whitespace, options)}#{val}"
|
540
|
+
if val_type == :value
|
541
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name} = #{expected}"
|
542
|
+
else
|
543
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name} =\n#{expected}"
|
544
|
+
end
|
545
|
+
|
546
|
+
append_value = ",#{create_simple_value(:whitespace, options)}"
|
547
|
+
append_expect = ",\n"
|
548
|
+
end
|
549
|
+
|
550
|
+
unless append_expect.empty?
|
551
|
+
append_expect = append_expect[1..-1]
|
552
|
+
end
|
553
|
+
unless append_expect.empty?
|
554
|
+
append_expect << " " * level
|
555
|
+
end
|
556
|
+
|
557
|
+
value_val << "#{" " * rand(0..10)}>"
|
558
|
+
value_expect << "#{append_expect}>"
|
559
|
+
|
560
|
+
when :implied_hash
|
561
|
+
options.merge!({ spaces_only: true })
|
562
|
+
|
563
|
+
name = create_simple_value(:value_name_simple, options)
|
564
|
+
value_val = "\#<#{name}#{" " * rand(1..10)}"
|
565
|
+
value_expect = "#{" " * level}\#<#{name}"
|
566
|
+
append_value = ""
|
567
|
+
append_expect = "\n"
|
568
|
+
|
569
|
+
rand(1..5).times do
|
570
|
+
hash_type = [:hash_key_reversed_symbol, :hash_key_symbol].sample
|
571
|
+
name = create_simple_value(hash_type, options)
|
572
|
+
val_type = [:class, :value, :hash, :array].sample
|
573
|
+
val_type = :value if level > 4 || rand(0.1) == 0
|
574
|
+
|
575
|
+
case val_type
|
576
|
+
when :class, :hash, :array
|
577
|
+
val, expected = create_value(level + 2, val_type, options)
|
578
|
+
|
579
|
+
when :value
|
580
|
+
val = create_simple_value([:value_simple, :value_string, :value_method, :value_complex_string].sample, options)
|
581
|
+
expected = val
|
582
|
+
end
|
583
|
+
|
584
|
+
case hash_type
|
585
|
+
when :hash_key_reversed_symbol
|
586
|
+
value_val << "#{append_value}#{name}#{" " * rand(0..10)}#{val}"
|
587
|
+
if val_type == :value
|
588
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name} #{expected}"
|
589
|
+
else
|
590
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name}\n#{expected}"
|
591
|
+
end
|
592
|
+
|
593
|
+
else
|
594
|
+
value_val << "#{append_value}#{name}#{" " * rand(0..10)}=>#{" " * rand(0..10)}#{val}"
|
595
|
+
if val_type == :value
|
596
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name} => #{expected}"
|
597
|
+
else
|
598
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name} =>\n#{expected}"
|
599
|
+
end
|
600
|
+
end
|
601
|
+
|
602
|
+
append_value = ",#{create_simple_value(:whitespace, options)}"
|
603
|
+
append_expect = ",\n"
|
604
|
+
end
|
605
|
+
|
606
|
+
value_val << "#{create_simple_value(:whitespace, options)}>"
|
607
|
+
value_expect << "\n#{" " * level}>"
|
608
|
+
|
609
|
+
when :hash
|
610
|
+
value_val = "{#{create_simple_value(:whitespace, options)}"
|
611
|
+
value_expect = "#{" " * level}{\n"
|
612
|
+
append_value = ""
|
613
|
+
append_expect = ""
|
614
|
+
|
615
|
+
rand(1..5).times do
|
616
|
+
hash_type = [:hash_key_string, :hash_key_complex_string, :hash_key_symbol, :hash_key_reversed_symbol].sample
|
617
|
+
name = create_simple_value(hash_type, options)
|
618
|
+
val_type = [:class, :value, :hash, :array].sample
|
619
|
+
val_type = :value if level > 4 || rand(0.1) == 0
|
620
|
+
|
621
|
+
case val_type
|
622
|
+
when :class, :hash, :array
|
623
|
+
val, expected = create_value(level + 2, val_type, options)
|
624
|
+
|
625
|
+
when :value
|
626
|
+
val = create_simple_value([:value_simple, :value_string, :value_method, :value_complex_string].sample, options)
|
627
|
+
expected = val
|
628
|
+
end
|
629
|
+
|
630
|
+
case hash_type
|
631
|
+
when :hash_key_reversed_symbol
|
632
|
+
value_val << "#{append_value}#{name}#{create_simple_value(:whitespace, options)}#{val}"
|
633
|
+
if val_type == :value
|
634
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name} #{expected}"
|
635
|
+
else
|
636
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name}\n#{expected}"
|
637
|
+
end
|
638
|
+
|
639
|
+
else
|
640
|
+
value_val << "#{append_value}#{name}#{create_simple_value(:whitespace, options)}=>#{create_simple_value(:whitespace, options)}#{val}"
|
641
|
+
if val_type == :value
|
642
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name} => #{expected}"
|
643
|
+
else
|
644
|
+
value_expect << "#{append_expect}#{" " * (level + 1)}#{name} =>\n#{expected}"
|
645
|
+
end
|
646
|
+
end
|
647
|
+
|
648
|
+
append_value = ",#{create_simple_value(:whitespace, options)}"
|
649
|
+
append_expect = ",\n"
|
650
|
+
end
|
651
|
+
|
652
|
+
value_val << "#{create_simple_value(:whitespace, options)}}"
|
653
|
+
value_expect << "\n#{" " * level}}"
|
654
|
+
|
655
|
+
when :array
|
656
|
+
value_val = "[#{create_simple_value(:whitespace, options)}"
|
657
|
+
value_expect = "#{" " * level}[\n"
|
658
|
+
append_value = ""
|
659
|
+
append_expect = ""
|
660
|
+
|
661
|
+
rand(1..5).times do
|
662
|
+
val_type = [:class, :value, :hash, :array].sample
|
663
|
+
val_type = :value if level > 4 || rand(0.1) == 0
|
664
|
+
|
665
|
+
case val_type
|
666
|
+
when :class, :hash, :array
|
667
|
+
val, expected = create_value(level + 1, val_type, options)
|
668
|
+
|
669
|
+
when :value
|
670
|
+
val = create_simple_value([:value_simple, :value_string, :value_method, :value_complex_string].sample, options)
|
671
|
+
expected = "#{" " * (level + 1)}#{val}"
|
672
|
+
end
|
673
|
+
|
674
|
+
value_val << "#{append_value}#{val}"
|
675
|
+
value_expect << "#{append_expect}#{expected}"
|
676
|
+
|
677
|
+
append_value = ",#{create_simple_value(:whitespace, options)}"
|
678
|
+
append_expect = ",\n"
|
679
|
+
end
|
680
|
+
|
681
|
+
value_val << "#{create_simple_value(:whitespace, options)}]"
|
682
|
+
value_expect << "\n#{" " * level}]"
|
683
|
+
end
|
684
|
+
|
685
|
+
[value_val, value_expect]
|
686
|
+
end
|
687
|
+
|
688
|
+
def expectation_in_text(expected_text, pre_text, post_text)
|
689
|
+
expected = "#{pre_text}#{expected_text}#{post_text}"
|
690
|
+
expected = expected.gsub("\n", "\n ") unless pre_text.empty?
|
691
|
+
expected = expected.gsub(post_text.gsub("\n", "\n "), post_text)
|
692
|
+
|
693
|
+
expected
|
694
|
+
end
|