teaspoon 0.7.9 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +382 -260
  3. data/app/assets/javascripts/teaspoon-angular.js +108 -26241
  4. data/app/assets/javascripts/teaspoon-jasmine.js +103 -2642
  5. data/app/assets/javascripts/teaspoon-mocha.js +109 -5416
  6. data/app/assets/javascripts/teaspoon-qunit.js +107 -2255
  7. data/app/assets/javascripts/teaspoon-teaspoon.js +0 -1
  8. data/app/assets/javascripts/teaspoon/angular.coffee +3 -1
  9. data/app/assets/javascripts/teaspoon/base/hook.coffee +21 -0
  10. data/app/assets/javascripts/teaspoon/base/reporters/html.coffee +26 -14
  11. data/app/assets/javascripts/teaspoon/base/reporters/html/progress_view.coffee +1 -1
  12. data/app/assets/javascripts/teaspoon/base/reporters/html/template.coffee +3 -3
  13. data/app/assets/javascripts/teaspoon/base/teaspoon.coffee +10 -1
  14. data/app/assets/javascripts/teaspoon/jasmine.coffee +3 -1
  15. data/app/assets/javascripts/teaspoon/mocha.coffee +3 -1
  16. data/app/assets/javascripts/teaspoon/mocha/reporters/html.coffee +1 -1
  17. data/app/assets/javascripts/teaspoon/qunit.coffee +3 -1
  18. data/app/assets/javascripts/teaspoon/qunit/reporters/html.coffee +1 -1
  19. data/app/assets/javascripts/teaspoon/teaspoon.coffee +0 -1
  20. data/app/assets/stylesheets/teaspoon.css +12 -8
  21. data/app/controllers/teaspoon/suite_controller.rb +32 -0
  22. data/app/views/teaspoon/suite/_body.html.erb +0 -0
  23. data/app/views/teaspoon/suite/_boot.html.erb +4 -0
  24. data/app/views/teaspoon/suite/_boot_require_js.html.erb +19 -0
  25. data/app/views/teaspoon/{spec/suites.html.erb → suite/index.html.erb} +6 -7
  26. data/app/views/teaspoon/suite/show.html.erb +19 -0
  27. data/bin/teaspoon +1 -1
  28. data/config/routes.rb +14 -4
  29. data/lib/generators/teaspoon/install/POST_INSTALL +2 -2
  30. data/lib/generators/teaspoon/install/install_generator.rb +22 -11
  31. data/lib/generators/teaspoon/install/templates/_body.html.erb +0 -0
  32. data/lib/generators/teaspoon/install/templates/_boot.html.erb +4 -0
  33. data/lib/generators/teaspoon/install/templates/jasmine/env.rb +11 -0
  34. data/lib/generators/teaspoon/install/templates/jasmine/env_comments.rb +182 -0
  35. data/lib/generators/teaspoon/install/templates/jasmine/spec_helper.coffee +8 -6
  36. data/lib/generators/teaspoon/install/templates/jasmine/spec_helper.js +8 -7
  37. data/lib/generators/teaspoon/install/templates/mocha/env.rb +11 -0
  38. data/lib/generators/teaspoon/install/templates/mocha/env_comments.rb +182 -0
  39. data/lib/generators/teaspoon/install/templates/mocha/spec_helper.coffee +13 -13
  40. data/lib/generators/teaspoon/install/templates/mocha/spec_helper.js +13 -13
  41. data/lib/generators/teaspoon/install/templates/qunit/env.rb +11 -0
  42. data/lib/generators/teaspoon/install/templates/qunit/env_comments.rb +182 -0
  43. data/lib/generators/teaspoon/install/templates/qunit/test_helper.coffee +6 -5
  44. data/lib/generators/teaspoon/install/templates/qunit/test_helper.js +6 -5
  45. data/lib/tasks/teaspoon.rake +9 -2
  46. data/lib/teaspoon.rb +4 -6
  47. data/lib/teaspoon/command_line.rb +116 -134
  48. data/lib/teaspoon/configuration.rb +144 -66
  49. data/lib/teaspoon/console.rb +70 -37
  50. data/lib/teaspoon/coverage.rb +42 -15
  51. data/lib/teaspoon/deprecated.rb +65 -0
  52. data/lib/teaspoon/drivers/base.rb +10 -0
  53. data/lib/teaspoon/drivers/phantomjs/runner.js +9 -11
  54. data/lib/teaspoon/drivers/phantomjs_driver.rb +21 -21
  55. data/lib/teaspoon/drivers/selenium_driver.rb +32 -13
  56. data/lib/teaspoon/engine.rb +32 -12
  57. data/lib/teaspoon/environment.rb +16 -12
  58. data/lib/teaspoon/exceptions.rb +41 -5
  59. data/lib/teaspoon/exporter.rb +52 -0
  60. data/lib/teaspoon/formatters/base.rb +171 -0
  61. data/lib/teaspoon/formatters/clean_formatter.rb +2 -4
  62. data/lib/teaspoon/formatters/documentation_formatter.rb +60 -0
  63. data/lib/teaspoon/formatters/dot_formatter.rb +12 -90
  64. data/lib/teaspoon/formatters/json_formatter.rb +36 -0
  65. data/lib/teaspoon/formatters/junit_formatter.rb +51 -32
  66. data/lib/teaspoon/formatters/modules/report_module.rb +76 -0
  67. data/lib/teaspoon/formatters/pride_formatter.rb +23 -27
  68. data/lib/teaspoon/formatters/snowday_formatter.rb +7 -11
  69. data/lib/teaspoon/formatters/swayze_or_oprah_formatter.rb +88 -64
  70. data/lib/teaspoon/formatters/tap_formatter.rb +18 -27
  71. data/lib/teaspoon/formatters/tap_y_formatter.rb +35 -45
  72. data/lib/teaspoon/formatters/teamcity_formatter.rb +69 -31
  73. data/lib/teaspoon/instrumentation.rb +33 -33
  74. data/lib/teaspoon/result.rb +2 -1
  75. data/lib/teaspoon/runner.rb +40 -28
  76. data/lib/teaspoon/server.rb +23 -25
  77. data/lib/teaspoon/suite.rb +52 -72
  78. data/lib/teaspoon/utility.rb +3 -14
  79. data/lib/teaspoon/version.rb +1 -1
  80. data/spec/dummy/app/assets/javascripts/integration/integration_spec.coffee +3 -0
  81. data/spec/dummy/app/assets/javascripts/integration/spec_helper.coffee +2 -0
  82. data/spec/dummy/config/application.rb +3 -0
  83. data/spec/features/console_reporter_spec.rb +48 -18
  84. data/spec/features/hooks_spec.rb +23 -41
  85. data/spec/features/html_reporter_spec.rb +38 -21
  86. data/spec/features/install_generator_spec.rb +34 -20
  87. data/spec/features/instrumentation_spec.rb +3 -2
  88. data/spec/fixtures/coverage.json +243 -0
  89. data/spec/javascripts/fixtures/_body.html.erb +1 -0
  90. data/spec/javascripts/jasmine_helper.coffee +1 -1
  91. data/spec/javascripts/teaspoon/base/fixture_spec.coffee +4 -4
  92. data/spec/javascripts/teaspoon/base/reporters/html_spec.coffee +9 -10
  93. data/spec/javascripts/teaspoon/mocha/reporters/html_mspec.coffee +0 -6
  94. data/spec/javascripts/teaspoon/phantomjs/runner_spec.coffee +5 -6
  95. data/spec/javascripts/turbolinks_helper.coffee +1 -1
  96. data/spec/spec_helper.rb +3 -4
  97. data/spec/teaspoon/command_line_spec.rb +139 -23
  98. data/spec/teaspoon/configuration_spec.rb +164 -46
  99. data/spec/teaspoon/console_spec.rb +142 -47
  100. data/spec/teaspoon/coverage_spec.rb +98 -28
  101. data/spec/teaspoon/drivers/base_spec.rb +5 -0
  102. data/spec/teaspoon/drivers/phantomjs_driver_spec.rb +32 -14
  103. data/spec/teaspoon/drivers/selenium_driver_spec.rb +32 -24
  104. data/spec/teaspoon/engine_spec.rb +8 -5
  105. data/spec/teaspoon/environment_spec.rb +56 -33
  106. data/spec/teaspoon/exceptions_spec.rb +57 -0
  107. data/spec/teaspoon/exporter_spec.rb +96 -0
  108. data/spec/teaspoon/formatters/base_spec.rb +259 -0
  109. data/spec/teaspoon/formatters/clean_formatter_spec.rb +37 -0
  110. data/spec/teaspoon/formatters/documentation_formatter_spec.rb +127 -0
  111. data/spec/teaspoon/formatters/dot_formatter_spec.rb +52 -56
  112. data/spec/teaspoon/formatters/json_formatter_spec.rb +77 -0
  113. data/spec/teaspoon/formatters/junit_formatter_spec.rb +72 -35
  114. data/spec/teaspoon/formatters/pride_formatter_spec.rb +37 -0
  115. data/spec/teaspoon/formatters/snowday_formatter_spec.rb +35 -0
  116. data/spec/teaspoon/formatters/tap_formatter_spec.rb +29 -81
  117. data/spec/teaspoon/formatters/tap_y_formatter_spec.rb +31 -141
  118. data/spec/teaspoon/formatters/teamcity_formatter_spec.rb +99 -42
  119. data/spec/teaspoon/instrumentation_spec.rb +44 -44
  120. data/spec/teaspoon/result_spec.rb +37 -0
  121. data/spec/teaspoon/runner_spec.rb +70 -59
  122. data/spec/teaspoon/server_spec.rb +34 -52
  123. data/spec/teaspoon/suite_spec.rb +42 -188
  124. data/spec/teaspoon_env.rb +39 -28
  125. data/vendor/assets/javascripts/{angular-scenario-1.0.5.js → angular/1.0.5.js} +0 -0
  126. data/vendor/assets/javascripts/{angular-scenario-1.0.5.MIT-LICENSE → angular/MIT-LICENSE} +0 -0
  127. data/vendor/assets/javascripts/{jasmine-1.3.1.js → jasmine/1.3.1.js} +0 -0
  128. data/vendor/assets/javascripts/jasmine/2.0.0.js +2412 -0
  129. data/vendor/assets/javascripts/{jasmine-1.3.1.MIT.LICENSE → jasmine/MIT.LICENSE} +0 -0
  130. data/vendor/assets/javascripts/{mocha-1.10.0.js → mocha/1.10.0.js} +1 -0
  131. data/vendor/assets/javascripts/mocha/1.17.1.js +5813 -0
  132. data/vendor/assets/javascripts/{mocha-1.10.1.MIT.LICENSE → mocha/MIT.LICENSE} +0 -0
  133. data/vendor/assets/javascripts/{qunit-1.12.0.js → qunit/1.12.0.js} +1 -1
  134. data/vendor/assets/javascripts/qunit/1.14.0.js +2288 -0
  135. data/vendor/assets/javascripts/{qunit-1.12.0.MIT.LICENSE → qunit/MIT.LICENSE} +0 -0
  136. data/vendor/assets/javascripts/support/chai.js +827 -385
  137. data/vendor/assets/javascripts/support/jasmine-jquery-1.7.0.js +720 -0
  138. data/vendor/assets/javascripts/support/jasmine-jquery-2.0.0.js +812 -0
  139. data/vendor/assets/javascripts/support/sinon-chai.js +17 -0
  140. data/vendor/assets/javascripts/support/sinon.js +1138 -643
  141. metadata +57 -36
  142. data/app/controllers/teaspoon/spec_controller.rb +0 -38
  143. data/app/helpers/teaspoon/spec_helper.rb +0 -36
  144. data/app/views/teaspoon/spec/_require_js.html.erb +0 -21
  145. data/app/views/teaspoon/spec/_standard.html.erb +0 -4
  146. data/app/views/teaspoon/spec/runner.html.erb +0 -19
  147. data/lib/generators/teaspoon/install/templates/env.rb +0 -38
  148. data/lib/generators/teaspoon/install/templates/jasmine/initializer.rb +0 -64
  149. data/lib/generators/teaspoon/install/templates/mocha/initializer.rb +0 -64
  150. data/lib/generators/teaspoon/install/templates/qunit/initializer.rb +0 -64
  151. data/lib/teaspoon/check_coverage.rb +0 -33
  152. data/lib/teaspoon/drivers/base_driver.rb +0 -10
  153. data/lib/teaspoon/exception_handling.rb +0 -18
  154. data/lib/teaspoon/formatters/base_formatter.rb +0 -63
  155. data/spec/dummy/config/initializers/teaspoon.rb +0 -41
  156. data/spec/teaspoon/check_coverage_spec.rb +0 -50
  157. data/spec/teaspoon/formatters/base_formatter_spec.rb +0 -45
  158. data/vendor/assets/javascripts/support/chai.MIT.LICENSE +0 -22
  159. data/vendor/assets/javascripts/support/expect.MIT.LICENSE +0 -22
  160. data/vendor/assets/javascripts/support/jasmine-jquery.MIT.LICENSE +0 -20
  161. data/vendor/assets/javascripts/support/jasmine-jquery.js +0 -659
  162. data/vendor/assets/javascripts/support/sinon-chai.MIT-ISH.LICENSE +0 -13
  163. data/vendor/assets/javascripts/support/sinon.BSD.LICENSE +0 -27
@@ -1,57 +1,65 @@
1
1
  require "spec_helper"
2
- require "teaspoon/drivers/selenium_driver"
3
2
 
4
3
  describe Teaspoon::Drivers::SeleniumDriver do
5
4
 
6
- describe "#run_specs" do
5
+ describe "#initialize" do
7
6
 
8
- before do
9
- @navigate = double(to: nil)
10
- @driver = double(quit: nil, navigate: @navigate, execute_script: nil)
11
- Selenium::WebDriver.stub(:for).and_return(@driver)
12
- @wait = double(until: nil)
13
- Selenium::WebDriver::Wait.stub(:new).and_return(@wait)
7
+ it "assigns @options" do
8
+ subject = Teaspoon::Drivers::SeleniumDriver.new(foo: "bar")
9
+ expect(subject.instance_variable_get(:@options)).to eq(foo: "bar")
10
+ end
11
+
12
+ it "accepts a string for options" do
13
+ subject = Teaspoon::Drivers::SeleniumDriver.new('{"foo":"bar"}')
14
+ expect(subject.instance_variable_get(:@options)).to eq("foo" => "bar")
15
+ end
16
+
17
+ it "raises a Teaspoon::UnknownDriverOptions exception if the options aren't understood" do
18
+ expect { Teaspoon::Drivers::SeleniumDriver.new(true) }.to raise_error(Teaspoon::UnknownDriverOptions)
14
19
  end
15
20
 
16
- it "instantiates the formatter" do
17
- runner = double(failure_count: nil)
18
- Teaspoon::Runner.should_receive(:new).and_return(runner)
19
- subject.run_specs(:default, "_url_")
21
+ it "raises a Teaspoon::UnknownDriverOptions exception if the options aren't parseable" do
22
+ expect { Teaspoon::Drivers::SeleniumDriver.new("{foo:bar}") }.to raise_error(Teaspoon::UnknownDriverOptions)
20
23
  end
21
24
 
22
- it "returns the number of failures from the runner" do
23
- runner = double(failure_count: 42)
24
- Teaspoon::Runner.should_receive(:new).and_return(runner)
25
- expect(subject.run_specs(:default, "_url_")).to be(42)
25
+ end
26
+
27
+ describe "#run_specs" do
28
+
29
+ let(:runner) { double }
30
+
31
+ before do
32
+ @driver = double(quit: nil, navigate: @navigate = double(to: nil), execute_script: nil)
33
+ Selenium::WebDriver.stub(:for).and_return(@driver)
34
+ Selenium::WebDriver::Wait.stub(:new).and_return(@wait = double(until: nil))
26
35
  end
27
36
 
28
37
  it "loads firefox for the webdriver" do
29
38
  Selenium::WebDriver.should_receive(:for).with(:firefox)
30
- subject.run_specs(:default, "_url_")
39
+ subject.run_specs(runner, "_url_")
31
40
  end
32
41
 
33
42
  it "navigates to the correct url" do
34
43
  @navigate.should_receive(:to).with("_url_")
35
- subject.run_specs(:default, "_url_")
44
+ subject.run_specs(runner, "_url_")
36
45
  end
37
46
 
38
47
  it "ensures quit is called on the driver" do
39
48
  @driver.should_receive(:quit)
40
- subject.run_specs(:default, "_url_")
49
+ subject.run_specs(runner, "_url_")
41
50
  end
42
51
 
43
52
  it "waits for the specs to complete, setting the interval, timeout and message" do
44
- Selenium::WebDriver::Wait.should_receive(:new).with(timeout: 180, interval: 0.01, message: "Timed out")
45
- subject.run_specs(:default, "_url_")
53
+ Selenium::WebDriver::Wait.should_receive(:new).with(HashWithIndifferentAccess.new(client_driver: :firefox, timeout: 180, interval: 0.01, message: "Timed out"))
54
+ subject.run_specs(runner, "_url_")
46
55
  end
47
56
 
48
57
  it "waits until it's done (checking Teaspoon.finished) and processes each line" do
49
- @block = nil
50
58
  @wait.should_receive(:until) { |&b| @block = b }
51
59
  @driver.should_receive(:execute_script).with("return window.Teaspoon && window.Teaspoon.finished").and_return(true)
52
60
  @driver.should_receive(:execute_script).with("return window.Teaspoon && window.Teaspoon.getMessages() || []").and_return(["_line_"])
53
- Teaspoon::Runner.any_instance.should_receive(:process).with("_line_\n")
54
- subject.run_specs(:default, "_url_")
61
+ runner.should_receive(:process).with("_line_\n")
62
+ subject.run_specs(runner, "_url_")
55
63
  @block.call
56
64
  end
57
65
 
@@ -2,13 +2,16 @@ require "spec_helper"
2
2
 
3
3
  describe Teaspoon::Engine do
4
4
 
5
- it "is a class" do
6
- Teaspoon::Engine.should be_a(Class)
7
- end
5
+ subject { Teaspoon::Engine }
8
6
 
9
7
  it "has been isolated with a name" do
10
- expect(Teaspoon::Engine.isolated?).to be(true)
11
- expect(Teaspoon::Engine.railtie_name).to eql("teaspoon")
8
+ expect(subject.isolated?).to be(true)
9
+ expect(subject.railtie_name).to eql("teaspoon")
10
+ end
11
+
12
+ it "defaults the root path" do
13
+ # this has to add spec/dummy as we set it manually
14
+ expect(Teaspoon.configuration.root.join('spec/dummy').to_s).to eq(Rails.root.to_s)
12
15
  end
13
16
 
14
17
  it "adds asset paths from configuration" do
@@ -19,58 +19,81 @@ describe Teaspoon::Environment do
19
19
  expect{ Teaspoon::Environment.load }.to raise_error("Rails environment not found.")
20
20
  end
21
21
 
22
- it "calls configure_from_options if the environment is ready" do
22
+ it "configures teaspoon from options if the environment is ready" do
23
23
  subject.should_receive(:rails_loaded?).and_return(true)
24
- subject.should_receive(:configure_from_options)
25
- Teaspoon::Environment.load
24
+ Teaspoon.configuration.should_receive(:override_from_options).with(foo: "bar")
25
+ Teaspoon::Environment.load(foo: "bar")
26
26
  end
27
27
 
28
28
  end
29
29
 
30
30
  describe ".require_environment" do
31
31
 
32
- it "allows passing an override" do
33
- subject.should_receive(:require_env).with(File.expand_path("override", Dir.pwd))
34
- subject.require_environment("override")
32
+ before do
33
+ File.stub(:exists?)
34
+ subject.stub(:require_env)
35
+ Teaspoon.configured = false
36
+ @orig_teaspoon_env = ENV['TEASPOON_ENV']
37
+ ENV['TEASPOON_ENV'] = nil
35
38
  end
36
39
 
37
- it "looks for the standard files" do
38
- subject.stub(:require_env)
39
- File.should_receive(:exists?).with(File.expand_path("spec/teaspoon_env.rb", Dir.pwd)).and_return(true)
40
- subject.should_receive(:require_env).with(File.expand_path("spec/teaspoon_env.rb", Dir.pwd))
41
- subject.require_environment
42
-
43
- File.should_receive(:exists?).with(File.expand_path("spec/teaspoon_env.rb", Dir.pwd)).and_return(false)
44
- File.should_receive(:exists?).with(File.expand_path("test/teaspoon_env.rb", Dir.pwd)).and_return(true)
45
- subject.should_receive(:require_env).with(File.expand_path("test/teaspoon_env.rb", Dir.pwd))
46
- subject.require_environment
47
-
48
- File.should_receive(:exists?).with(File.expand_path("spec/teaspoon_env.rb", Dir.pwd)).and_return(false)
49
- File.should_receive(:exists?).with(File.expand_path("test/teaspoon_env.rb", Dir.pwd)).and_return(false)
50
- File.should_receive(:exists?).with(File.expand_path("teaspoon_env.rb", Dir.pwd)).and_return(true)
51
- subject.should_receive(:require_env).with(File.expand_path("teaspoon_env.rb", Dir.pwd))
52
- subject.require_environment
40
+ after do
41
+ Teaspoon.configured = true
42
+ ENV['TEASPOON_ENV'] = @orig_teaspoon_env
53
43
  end
54
44
 
55
- it "raises if no env file was found" do
56
- File.stub(:exists?)
57
- expect{ subject.require_environment }.to raise_error(Teaspoon::EnvironmentNotFound)
45
+ describe "when loading with an override" do
46
+
47
+ before do
48
+ subject.should_receive(:require_env).and_call_original
49
+ end
50
+
51
+ it "allows passing an override" do
52
+ expanded = File.expand_path("_override_", Dir.pwd)
53
+ ::Kernel.should_receive(:load).with(expanded)
54
+ subject.require_environment("_override_")
55
+ end
56
+
57
+ it "sets the TEASPOON_ENV" do
58
+ expanded = File.expand_path("../../_override_file_", Dir.pwd)
59
+ ::Kernel.should_receive(:load).with(expanded)
60
+ subject.require_environment("../../_override_file_")
61
+ expect(ENV["TEASPOON_ENV"]).to eq(expanded)
62
+ end
63
+
58
64
  end
59
- end
60
65
 
61
- describe ".standard_environments" do
66
+ describe "when loading from defaults" do
67
+
68
+ it "looks for the standard files" do
69
+ File.should_receive(:exists?).with(File.expand_path("spec/teaspoon_env.rb", Dir.pwd)).and_return(true)
70
+ subject.should_receive(:require_env).with(File.expand_path("spec/teaspoon_env.rb", Dir.pwd))
71
+ subject.require_environment
72
+
73
+ File.should_receive(:exists?).with(File.expand_path("spec/teaspoon_env.rb", Dir.pwd)).and_return(false)
74
+ File.should_receive(:exists?).with(File.expand_path("test/teaspoon_env.rb", Dir.pwd)).and_return(true)
75
+ subject.should_receive(:require_env).with(File.expand_path("test/teaspoon_env.rb", Dir.pwd))
76
+ subject.require_environment
77
+
78
+ File.should_receive(:exists?).with(File.expand_path("spec/teaspoon_env.rb", Dir.pwd)).and_return(false)
79
+ File.should_receive(:exists?).with(File.expand_path("test/teaspoon_env.rb", Dir.pwd)).and_return(false)
80
+ File.should_receive(:exists?).with(File.expand_path("teaspoon_env.rb", Dir.pwd)).and_return(true)
81
+ subject.should_receive(:require_env).with(File.expand_path("teaspoon_env.rb", Dir.pwd))
82
+ subject.require_environment
83
+ end
84
+
85
+ it "raises if no env file was found" do
86
+ expect{ subject.require_environment }.to raise_error(Teaspoon::EnvironmentNotFound)
87
+ end
62
88
 
63
- it "returns an array" do
64
- expect(subject.standard_environments).to eql(["spec/teaspoon_env.rb", "test/teaspoon_env.rb", "teaspoon_env.rb"])
65
89
  end
66
90
 
67
91
  end
68
92
 
69
- describe ".configure_from_options" do
93
+ describe ".standard_environments" do
70
94
 
71
- it "allows overriding configuration directives from options" do
72
- Teaspoon.configuration.should_receive(:color=).with(false)
73
- Teaspoon::Environment.configure_from_options(color: false)
95
+ it "returns an array" do
96
+ expect(subject.standard_environments).to eql(["spec/teaspoon_env.rb", "test/teaspoon_env.rb", "teaspoon_env.rb"])
74
97
  end
75
98
 
76
99
  end
@@ -0,0 +1,57 @@
1
+ require "spec_helper"
2
+
3
+ describe Teaspoon::ExceptionHandling do
4
+
5
+ subject { Teaspoon::ExceptionHandling }
6
+
7
+ before do
8
+ @orig_debug = Rails.application.config.assets.debug
9
+ @orig_show_exceptions = Rails.application.config.action_dispatch.show_exceptions
10
+ end
11
+
12
+ after do
13
+ Rails.application.config.assets.debug = @orig_debug
14
+ Rails.application.config.action_dispatch.show_exceptions = @orig_show_exceptions
15
+ end
16
+
17
+ describe ".add_rails_handling" do
18
+
19
+ before do
20
+ subject.stub(:render_exceptions_with_javascript)
21
+ end
22
+
23
+ it "sets config.assets.debug to false" do
24
+ subject.add_rails_handling
25
+ expect(Rails.application.config.assets.debug).to be_false
26
+ end
27
+
28
+ it "sets config.action_dispatch.show_exceptions to true" do
29
+ subject.add_rails_handling
30
+ expect(Rails.application.config.action_dispatch.show_exceptions).to be_true
31
+ end
32
+
33
+ it "calls #render_exceptions_with_javascript" do
34
+ subject.should_receive(:render_exceptions_with_javascript)
35
+ subject.add_rails_handling
36
+ end
37
+
38
+ end
39
+
40
+ describe "ActionDispatch::DebugExceptions#render_exception mixin" do
41
+
42
+ before do
43
+ subject.add_rails_handling
44
+ end
45
+
46
+ let(:middleware) { ActionDispatch::DebugExceptions.new(app, nil) }
47
+ let(:app) { double(:app) }
48
+ let(:env) { double(:env, "[]" => []) }
49
+
50
+ it "responds with a javascript tag that raises the error" do
51
+ response = middleware.send(:render_exception, env, Exception.new("_message_"))
52
+ expect(response).to eq([200, {"Content-Type"=>"text/html;", "Content-Length"=>"54"}, ["<script>throw Error(\"Exception: _message_\\n\")</script>"]])
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+ require "teaspoon/exporter"
3
+
4
+ describe Teaspoon::Exporter do
5
+
6
+ subject { Teaspoon::Exporter.new(:suite_name, "http://666.420.42.0:31337/url/to/teaspoon", "_output_path_") }
7
+
8
+ describe "#initialize" do
9
+
10
+ it "assigns @suite and @url" do
11
+ expect(subject.instance_variable_get(:@suite)).to eq(:suite_name)
12
+ expect(subject.instance_variable_get(:@url)).to eq("http://666.420.42.0:31337/url/to/teaspoon")
13
+ end
14
+
15
+ it "expands the @output_path" do
16
+ expected = File.join(File.expand_path("_output_path_"), "suite_name")
17
+ expect(subject.instance_variable_get(:@output_path)).to eq(expected)
18
+ end
19
+
20
+ end
21
+
22
+ describe "#export" do
23
+
24
+ before do
25
+ Dir.should_receive(:mktmpdir).and_yield("_temp_path_")
26
+ subject.stub(:executable).and_return("/path/to/executable")
27
+ subject.stub(:`)
28
+ end
29
+
30
+ it "makes a temp directory and cds to it" do
31
+ Dir.should_receive(:chdir).with("_temp_path_")
32
+ subject.export
33
+ end
34
+
35
+ it "executes the wget call and creates the export" do
36
+ `(exit 0)`
37
+ Dir.should_receive(:chdir).with("_temp_path_").and_yield
38
+ subject.should_receive(:`).with("/path/to/executable --convert-links --adjust-extension --page-requisites --span-hosts http://666.420.42.0:31337/url/to/teaspoon 2>&1")
39
+ subject.should_receive(:create_export).with("_temp_path_/666.420.42.0:31337")
40
+ subject.export
41
+ end
42
+
43
+ it "raises a Teaspoon::ExporterException if the command failed for some reason" do
44
+ `(exit 1)`
45
+ Dir.should_receive(:chdir).with("_temp_path_").and_yield
46
+ expect { subject.export }.to raise_error Teaspoon::ExporterException, "Unable to export suite_name suite."
47
+ end
48
+
49
+ it "raises a Teaspoon::MissingDependency if wget wasn't found" do
50
+ Dir.should_receive(:chdir).with("_temp_path_").and_yield
51
+ subject.should_receive(:executable).and_call_original
52
+ subject.should_receive(:which).with("wget").and_return(nil)
53
+ expect { subject.export }.to raise_error Teaspoon::MissingDependency, "Could not find wget for exporting."
54
+ end
55
+
56
+ describe "creating the export" do
57
+
58
+ before do
59
+ `(exit 0)`
60
+ Dir.should_receive(:chdir).with("_temp_path_").and_yield
61
+ Dir.should_receive(:chdir).with("_temp_path_/666.420.42.0:31337").and_yield
62
+
63
+ File.stub(:read).and_return("")
64
+ File.stub(:write)
65
+ FileUtils.stub(:mkdir_p)
66
+ FileUtils.stub(:rm_r)
67
+ FileUtils.stub(:mv)
68
+ end
69
+
70
+ it "updates the relative paths" do
71
+ File.should_receive(:read).with(".#{Teaspoon.configuration.mount_at}/suite_name.html").and_return('"../../path/to/asset')
72
+ File.should_receive(:write).with("index.html", '"../path/to/asset')
73
+ subject.export
74
+ end
75
+
76
+ it "cleans up the old files" do
77
+ subject.stub(:move_output)
78
+ Dir.should_receive(:[]).once.with("{.#{Teaspoon.configuration.mount_at},robots.txt.html}").and_return(["./teaspoon", "robots.txt.html"])
79
+ FileUtils.should_receive(:rm_r).with(["./teaspoon", "robots.txt.html"])
80
+ subject.export
81
+ end
82
+
83
+ it "moves the files into the output path" do
84
+ subject.stub(:cleanup_output)
85
+ output_path = subject.instance_variable_get(:@output_path)
86
+ Dir.should_receive(:[]).and_return(["1", "2"])
87
+ FileUtils.should_receive(:mkdir_p).with(output_path)
88
+ FileUtils.should_receive(:mv).with(["1", "2"], output_path, force: true)
89
+ subject.export
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,259 @@
1
+ require "spec_helper"
2
+
3
+ describe Teaspoon::Formatters::Base do
4
+
5
+ let(:passing_spec) { double(passing?: true) }
6
+ let(:pending_spec) { double(passing?: false, pending?: true) }
7
+ let(:failing_spec) { double(passing?: false, pending?: false) }
8
+ let(:result) { double }
9
+
10
+ before do
11
+ @log = ""
12
+ STDOUT.stub(:print) { |s| @log << s }
13
+ end
14
+
15
+ describe "#initialize" do
16
+
17
+ subject { Teaspoon::Formatters::Base.new(:foo, "_output_file_") }
18
+
19
+ before do
20
+ File.stub(:open)
21
+ end
22
+
23
+ it "assigns various instance vars" do
24
+ expect(subject.instance_variable_get(:@suite_name)).to eq("foo")
25
+ expect(subject.instance_variable_get(:@output_file)).to eq("_output_file_")
26
+ expect(subject.instance_variable_get(:@stdout)).to eq("")
27
+ expect(subject.instance_variable_get(:@suite)).to eq(nil)
28
+ expect(subject.instance_variable_get(:@last_suite)).to eq(nil)
29
+ end
30
+
31
+ it "assigns @total_count, @run_count, and arrays for tracking results" do
32
+ expect(subject.total_count).to eq(0)
33
+ expect(subject.run_count).to eq(0)
34
+ expect(subject.passes).to eq([])
35
+ expect(subject.pendings).to eq([])
36
+ expect(subject.failures).to eq([])
37
+ expect(subject.errors).to eq([])
38
+ end
39
+
40
+ it "writes a new output file if one is specified" do
41
+ File.should_receive(:open).with("_output_file_", "w")
42
+ subject
43
+ end
44
+
45
+ end
46
+
47
+ describe "#runner" do
48
+
49
+ let(:result) { double(total: 666) }
50
+
51
+ it "sets @total_count" do
52
+ subject.runner(result)
53
+ expect(subject.total_count).to eq(666)
54
+ end
55
+
56
+ it "calls #log_runner when appropriate" do
57
+ subject.should_receive(:log_runner).with(result)
58
+ subject.runner(result)
59
+
60
+ subject.should_not_receive(:log_runner)
61
+ subject.runner(result, false)
62
+ end
63
+
64
+ end
65
+
66
+ describe "#suite" do
67
+
68
+ it "sets @suite, and @last_suite to the result" do
69
+ subject.suite(result)
70
+ expect(subject.instance_variable_get(:@suite)).to eq(result)
71
+ expect(subject.instance_variable_get(:@last_suite)).to eq(result)
72
+ end
73
+
74
+ it "calls #log_suite when appropriate" do
75
+ subject.should_receive(:log_suite).with(result)
76
+ subject.suite(result)
77
+
78
+ subject.should_not_receive(:log_suite)
79
+ subject.suite(result, false)
80
+ end
81
+
82
+ end
83
+
84
+ describe "#spec" do
85
+
86
+ it "increments the run count" do
87
+ subject.spec(failing_spec)
88
+ expect(subject.run_count).to eq(1)
89
+ subject.spec(failing_spec)
90
+ expect(subject.run_count).to eq(2)
91
+ end
92
+
93
+ it "adds to the correct array on passing results" do
94
+ subject.spec(passing_spec)
95
+ expect(subject.run_count).to eq(1)
96
+ expect(subject.passes).to eq([passing_spec])
97
+ end
98
+
99
+ it "adds to the correct array on pending results" do
100
+ subject.spec(pending_spec)
101
+ expect(subject.run_count).to eq(1)
102
+ expect(subject.pendings).to eq([pending_spec])
103
+ end
104
+
105
+ it "adds to the correct array on failing results" do
106
+ subject.spec(failing_spec)
107
+ expect(subject.run_count).to eq(1)
108
+ expect(subject.failures).to eq([failing_spec])
109
+ end
110
+
111
+ it "calls #log_spec when appropriate" do
112
+ subject.should_receive(:log_spec).with(failing_spec)
113
+ subject.spec(failing_spec)
114
+
115
+ subject.should_not_receive(:log_spec)
116
+ subject.spec(failing_spec, false)
117
+ end
118
+
119
+ it "clears @stdout" do
120
+ subject.instance_variable_set(:@stdout, "----")
121
+ subject.spec(failing_spec)
122
+ expect(subject.instance_variable_get(:@stdout)).to eq("")
123
+ end
124
+
125
+ end
126
+
127
+ describe "#error" do
128
+
129
+ it "tracks the error" do
130
+ subject.error(result)
131
+ expect(subject.errors).to eq([result])
132
+ end
133
+
134
+ it "calls #log_error when appropriate" do
135
+ subject.should_receive(:log_error).with(result)
136
+ subject.error(result)
137
+
138
+ subject.should_not_receive(:log_error)
139
+ subject.error(result, false)
140
+ end
141
+
142
+ end
143
+
144
+ describe "#exception" do
145
+
146
+ it "calls #log_exception when appropriate" do
147
+ subject.should_receive(:log_exception).with(result)
148
+ subject.exception(result)
149
+
150
+ subject.should_not_receive(:log_exception)
151
+ subject.exception(result, false)
152
+ end
153
+
154
+ end
155
+
156
+ describe "#console" do
157
+
158
+ it "adds the string to @stdout" do
159
+ subject.console("_message1_")
160
+ subject.console("_message2_")
161
+ expect(subject.instance_variable_get(:@stdout)).to eq("_message1__message2_")
162
+ end
163
+
164
+ it "calls #log_console when appropriate" do
165
+ subject.should_receive(:log_console).with("_message_")
166
+ subject.console("_message_")
167
+
168
+ subject.should_not_receive(:log_console)
169
+ subject.console("_message_", false)
170
+ end
171
+
172
+ end
173
+
174
+ describe "#result" do
175
+
176
+ let(:result) { double(coverage: nil) }
177
+
178
+ it "calls #log_result when appropriate" do
179
+ subject.should_receive(:log_result).with(result)
180
+ subject.result(result)
181
+
182
+ subject.should_not_receive(:log_result)
183
+ subject.result(result, false)
184
+ end
185
+
186
+ end
187
+
188
+ describe "#coverage" do
189
+
190
+ it "calls #log_coverage when appropriate" do
191
+ subject.should_receive(:log_coverage).with("_message_")
192
+ subject.coverage("_message_")
193
+
194
+ subject.should_receive(:log_coverage).with("_message_")
195
+ subject.coverage("_message_")
196
+ end
197
+
198
+ end
199
+
200
+ describe "#threshold_failure" do
201
+
202
+ it "calls #log_threshold_failure when appropriate" do
203
+ subject.should_receive(:log_threshold_failure).with("_message_")
204
+ subject.threshold_failure("_message_")
205
+
206
+ subject.should_receive(:log_threshold_failure).with("_message_")
207
+ subject.threshold_failure("_message_")
208
+ end
209
+
210
+ end
211
+
212
+ describe "#complete" do
213
+
214
+ it "calls #log_complete when appropriate" do
215
+ subject.should_receive(:log_complete).with(42)
216
+ subject.complete(42)
217
+
218
+ subject.should_receive(:log_complete).with(0)
219
+ subject.complete(0)
220
+ end
221
+
222
+ end
223
+
224
+ describe "#log_spec" do
225
+
226
+ it "calls #log_passing_spec on passing results" do
227
+ subject.should_receive(:log_passing_spec).with(passing_spec)
228
+ subject.send(:log_spec, passing_spec)
229
+ end
230
+
231
+ it "calls #log_pending_spec on pending results" do
232
+ subject.should_receive(:log_pending_spec).with(pending_spec)
233
+ subject.send(:log_spec, pending_spec)
234
+ end
235
+
236
+ it "calls #log_failing_spec on failing results" do
237
+ subject.should_receive(:log_failing_spec).with(failing_spec)
238
+ subject.send(:log_spec, failing_spec)
239
+ end
240
+
241
+ end
242
+
243
+ describe "logging to file" do
244
+
245
+ it "logs to a file" do
246
+ handle = double(write: nil)
247
+ File.should_receive(:open).with("_output_file_", "a").and_yield(handle)
248
+ handle.should_receive(:write).with("_str_")
249
+ subject.send(:log_to_file, "_str_", "_output_file_")
250
+ end
251
+
252
+ it "raises a Teaspoon::FileNotWritable exception if the file can't be written to" do
253
+ File.should_receive(:open).and_raise(IOError, "_io_error_message_")
254
+ expect { subject.send(:log_to_file, "_str_", "_output_file_") }.to raise_error(Teaspoon::FileNotWritable, "_io_error_message_")
255
+ end
256
+
257
+ end
258
+
259
+ end