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
@@ -0,0 +1 @@
1
+ This is a body partial.
@@ -1,3 +1,3 @@
1
1
  #= require jquery
2
- #= require support/jasmine-jquery
2
+ #= require support/jasmine-jquery-1.7.0
3
3
  #= require ./spec_helper
@@ -21,8 +21,8 @@ describe "Teaspoon.fixture", ->
21
21
 
22
22
  it "loads all of the files requested", ->
23
23
  fixture.load("fixture.html", "fixture.json")
24
- expect(@xhrSpy).toHaveBeenCalledWith("GET", "/teaspoon/fixtures/fixture.html", false)
25
- expect(@xhrSpy).toHaveBeenCalledWith("GET", "/teaspoon/fixtures/fixture.json", false)
24
+ expect(@xhrSpy).toHaveBeenCalledWith("GET", "#{Teaspoon.root}/fixtures/fixture.html", false)
25
+ expect(@xhrSpy).toHaveBeenCalledWith("GET", "#{Teaspoon.root}/fixtures/fixture.json", false)
26
26
 
27
27
  it "caches the type/contents of those files", ->
28
28
  fixture.load("fixture.html")
@@ -83,8 +83,8 @@ describe "Teaspoon.fixture", ->
83
83
 
84
84
  it "loads all of the files requested", ->
85
85
  fixture.preload("fixture.html", "fixture.json")
86
- expect(@xhrSpy).toHaveBeenCalledWith("GET", "/teaspoon/fixtures/fixture.html", false)
87
- expect(@xhrSpy).toHaveBeenCalledWith("GET", "/teaspoon/fixtures/fixture.json", false)
86
+ expect(@xhrSpy).toHaveBeenCalledWith("GET", "#{Teaspoon.root}/fixtures/fixture.html", false)
87
+ expect(@xhrSpy).toHaveBeenCalledWith("GET", "#{Teaspoon.root}/fixtures/fixture.json", false)
88
88
  expect(document.getElementById("teaspoon-fixtures")).toBe(null)
89
89
 
90
90
  it "caches the type/contents of those files", ->
@@ -29,12 +29,11 @@ describe "Teaspoon.Reporters.HTML", ->
29
29
  describe "constructor", ->
30
30
 
31
31
  it "sets up the expected variables", ->
32
-
33
32
  expect(@reporter.start).toBeDefined()
34
33
  expect(@reporter.config).toEqual("use-catch": true, "build-full-report": false, "display-progress": true)
35
34
  expect(@reporter.total).toEqual({exist: 0, run: 0, passes: 0, failures: 0, skipped: 0})
36
35
  expect(@reporter.views).toEqual({specs: {}, suites: {}})
37
- expect(@reporter.filters).toEqual(["by match: foo <a href='/teaspoon/default'>remove</a>"])
36
+ expect(@reporter.filters).toEqual(["by match: foo"])
38
37
 
39
38
  it "calls readConfig", ->
40
39
  expect(@readConfigSpy).toHaveBeenCalled()
@@ -110,7 +109,7 @@ describe "Teaspoon.Reporters.HTML", ->
110
109
  it "builds a select that displays the suites", ->
111
110
  result = @reporter.buildSuiteSelect()
112
111
  expect(result).toContain("select id=")
113
- expect(result).toContain("selected='selected' value=\"foo\"")
112
+ expect(result).toContain("selected value=\"#{Teaspoon.root}/foo\"")
114
113
 
115
114
 
116
115
  describe "#buildProgress", ->
@@ -339,8 +338,8 @@ describe "Teaspoon.Reporters.HTML", ->
339
338
 
340
339
  it "sets a class and the html for the filter display", ->
341
340
  expect(@reporter.filters.length).toBe(2)
342
- expect(@reporter.filters[0]).toBe("by file: _file_ <a href='/teaspoon/default'>remove</a>")
343
- expect(@reporter.filters[1]).toBe("by match: _grep_ <a href='/teaspoon/default'>remove</a>")
341
+ expect(@reporter.filters[0]).toBe("by file: _file_")
342
+ expect(@reporter.filters[1]).toBe("by match: _grep_")
344
343
 
345
344
 
346
345
  describe "#readConfig", ->
@@ -348,26 +347,26 @@ describe "Teaspoon.Reporters.HTML", ->
348
347
  beforeEach ->
349
348
  @readConfigSpy.andCallThrough()
350
349
  @config = {}
351
- @cookieSpy = spyOn(@reporter, "cookie").andReturn(@config)
350
+ @storeSpy = spyOn(@reporter, "store").andReturn(@config)
352
351
  @reporter.readConfig()
353
352
 
354
353
  it "reads the configuration from the cookie", ->
355
- expect(@cookieSpy).toHaveBeenCalledWith("teaspoon")
354
+ expect(@storeSpy).toHaveBeenCalledWith("teaspoon")
356
355
  expect(@reporter.config).toEqual(@config)
357
356
 
358
357
 
359
358
  describe "#toggleConfig", ->
360
359
 
361
360
  beforeEach ->
362
- @refreshSpy = spyOn(@reporter, "refresh")
363
- @cookieSpy = spyOn(@reporter, "cookie")
361
+ @refreshSpy = spyOn(Teaspoon, "reload")
362
+ @storeSpy = spyOn(@reporter, "store")
364
363
  @reporter.toggleConfig(target: {tagName: "button", getAttribute: -> "teaspoon-use-catch"})
365
364
 
366
365
  it "toggles the configuration", ->
367
366
  expect(@reporter.config["use-catch"]).toBe(false)
368
367
 
369
368
  it "sets the cookie", ->
370
- expect(@cookieSpy).toHaveBeenCalledWith("teaspoon", @reporter.config)
369
+ expect(@storeSpy).toHaveBeenCalledWith("teaspoon", @reporter.config)
371
370
 
372
371
  it "refreshes the page", ->
373
372
  expect(@refreshSpy).toHaveBeenCalled()
@@ -26,12 +26,6 @@ describe "Mocha Teaspoon.Reporters.HTML", ->
26
26
  expect(spec.err).to.eql(foo: "bar")
27
27
 
28
28
 
29
- describe "#envInfo", ->
30
-
31
- it "returns the version", ->
32
- expect(@reporter.envInfo()).to.be("mocha 1.9.1")
33
-
34
-
35
29
  describe "Mocha Teaspoon.Reporters.HTML.SpecView", ->
36
30
 
37
31
  describe "#updateState", ->
@@ -93,8 +93,7 @@ describe "PhantomJS Runner", ->
93
93
 
94
94
  it "logs the error message", ->
95
95
  @runner.fail("_message_")
96
- expect(@logSpy).toHaveBeenCalledWith("Error: _message_")
97
- expect(@logSpy).toHaveBeenCalledWith('{"_teaspoon":true,"type":"exception"}')
96
+ expect(@logSpy).toHaveBeenCalledWith('{"_teaspoon":true,"type":"exception","message":"_message_"}')
98
97
 
99
98
  it "exits with the error code", ->
100
99
  spy = spyOn(phantom, "exit")
@@ -104,10 +103,6 @@ describe "PhantomJS Runner", ->
104
103
 
105
104
  describe "#finish", ->
106
105
 
107
- it "logs an empty string (to fix line feeds in the console)", ->
108
- @runner.finish()
109
- expect(@logSpy).toHaveBeenCalledWith(" ")
110
-
111
106
  it "calls exit with a success code", ->
112
107
  spy = spyOn(phantom, "exit")
113
108
  @runner.finish()
@@ -133,6 +128,10 @@ describe "PhantomJS Runner", ->
133
128
  @callbacks.onError("_message_", ["trace1", "trace2"])
134
129
  expect(@logSpy).toHaveBeenCalledWith('{"_teaspoon":true,"type":"error","message":"_message_","trace":["trace1","trace2"]}')
135
130
 
131
+ it "calls #fail if the error is a TeaspoonError", ->
132
+ spyOn(@runner, "fail")
133
+ @callbacks.onError("TeaspoonError: _message_")
134
+ expect(@runner.fail).toHaveBeenCalledWith("Execution halted.")
136
135
 
137
136
  describe "#onConsoleMessage", ->
138
137
 
@@ -1,2 +1,2 @@
1
1
  #= require turbolinks
2
- #= require ./spec_helper
2
+ #= require ./spec_helper
data/spec/spec_helper.rb CHANGED
@@ -2,22 +2,21 @@ ENV["RAILS_ENV"] ||= "test"
2
2
  ENV["RAILS_ROOT"] = File.expand_path("../dummy", __FILE__)
3
3
  require File.expand_path("../dummy/config/environment", __FILE__)
4
4
 
5
+ require "coveralls"
6
+ Coveralls.wear!
7
+
5
8
  require "rspec/rails"
6
9
  require "rspec/autorun"
7
10
  require "capybara/rails"
8
- #require 'capybara/poltergeist'
9
11
  require "aruba/api"
10
12
 
11
13
  require "ostruct"
12
14
 
13
15
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each { |f| require f }
14
16
 
15
- #Capybara.javascript_driver = :poltergeist
16
-
17
17
  RSpec.configure do |config|
18
18
  config.infer_base_class_for_anonymous_controllers = false
19
19
  config.order = "random"
20
20
 
21
- config.filter_run :focus => true
22
21
  config.run_all_when_everything_filtered = true
23
22
  end
@@ -2,47 +2,163 @@ require "spec_helper"
2
2
  require "teaspoon/command_line"
3
3
  require "teaspoon/console"
4
4
 
5
+ module Kernel
6
+ def suppress_warnings
7
+ original_verbosity = $VERBOSE
8
+ $VERBOSE = nil
9
+ result = yield
10
+ $VERBOSE = original_verbosity
11
+ return result
12
+ end
13
+ end
14
+
5
15
  describe Teaspoon::CommandLine do
6
16
 
7
- describe "#initialize" do
17
+ subject { Teaspoon::CommandLine }
8
18
 
9
- let(:console) { double(execute: false) }
10
- let(:parser) { double(parse!: ["file1", "file2"]) }
19
+ let(:console) { double(failures?: false) }
20
+ let(:parser) { double(parse!: ["file1", "file2"]) }
21
+
22
+ describe "#initialize" do
11
23
 
12
24
  before do
13
- Teaspoon::CommandLine.any_instance.stub(:abort)
14
25
  Teaspoon::Console.stub(:new).and_return(console)
15
- Teaspoon::CommandLine.any_instance.stub(:opt_parser).and_return(parser)
16
- end
17
-
18
- it "assigns @options" do
19
- instance = Teaspoon::CommandLine.new
20
- expect(instance.instance_variable_get(:@options)).to eq({})
26
+ subject.any_instance.stub(:abort)
27
+ subject.any_instance.stub(:opt_parser).and_return(parser)
21
28
  end
22
29
 
23
- it "assigns @files" do
24
- instance = Teaspoon::CommandLine.new
25
- expect(instance.instance_variable_get(:@files)).to eq(["file1", "file2"])
30
+ it "assigns @options and adds the files that were parsed out" do
31
+ expect(subject.new.instance_variable_get(:@options)).to eq(files: ["file1", "file2"])
26
32
  end
27
33
 
28
34
  it "aborts with a message on Teaspoon::EnvironmentNotFound" do
29
35
  Teaspoon::Console.should_receive(:new).and_raise(Teaspoon::EnvironmentNotFound)
30
- Teaspoon::CommandLine.any_instance.should_receive(:abort)
31
- STDOUT.should_receive(:print).with("Unable to load Teaspoon environment in {spec/teaspoon_env.rb, test/teaspoon_env.rb, teaspoon_env.rb}.\n")
32
- STDOUT.should_receive(:print).with("Consider using -r path/to/teaspoon_env\n")
33
- Teaspoon::CommandLine.new
36
+ subject.any_instance.should_receive(:abort).with("Teaspoon::EnvironmentNotFound\nConsider using -r path/to/teaspoon_env\n")
37
+ subject.new
34
38
  end
35
39
 
36
40
  it "executes using Teaspoon::Console" do
37
- Teaspoon::Console.should_receive(:new).with({}, ["file1", "file2"])
38
- console.should_receive(:execute)
39
- Teaspoon::CommandLine.new
41
+ Teaspoon::Console.should_receive(:new).with(files: ["file1", "file2"])
42
+ console.should_receive(:failures?)
43
+ subject.new
40
44
  end
41
45
 
42
46
  it "aborts if Teaspoon::Console fails" do
43
- Teaspoon::CommandLine.any_instance.should_receive(:abort)
44
- console.should_receive(:execute).and_return(true)
45
- Teaspoon::CommandLine.new
47
+ subject.any_instance.should_receive(:abort)
48
+ console.should_receive(:failures?).and_return(true)
49
+ subject.new
50
+ end
51
+
52
+ it "logs a message and exits on abort" do
53
+ STDOUT.should_receive(:print).with("Teaspoon::EnvironmentNotFound\nConsider using -r path/to/teaspoon_env\n")
54
+ Teaspoon::Console.should_receive(:new).and_raise(Teaspoon::EnvironmentNotFound)
55
+ subject.any_instance.should_receive(:abort).and_call_original
56
+ expect { subject.new }.to raise_error SystemExit
57
+ end
58
+
59
+ end
60
+
61
+ describe "opt_parser" do
62
+
63
+ before do
64
+ @log = ""
65
+ STDOUT.stub(:print) { |s| @log << s }
66
+ Teaspoon::Console.stub(:new).and_return(console)
67
+ end
68
+
69
+ it "has --help" do
70
+ suppress_warnings { ARGV = ["--help"] }
71
+ expect { subject.new.opt_parser }.to raise_error SystemExit
72
+ expect(@log).to include <<-OUTPUT.strip_heredoc
73
+ Usage: teaspoon [options] [files]
74
+
75
+ -r, --require FILE Require Teaspoon environment file.
76
+ -d, --driver DRIVER Specify driver:
77
+ phantomjs (default)
78
+ selenium
79
+ --driver-options OPTIONS Specify driver-specific options to pass into the driver.
80
+ e.g. "--ssl-protocol=any --ssl-certificates-path=/path/to/certs".
81
+ Driver options are only supported with phantomjs.
82
+ --driver-timeout SECONDS Sets the timeout for the driver to wait before exiting.
83
+ --server SERVER Sets server to use with Rack.
84
+ e.g. webrick, thin
85
+ --server-port PORT Sets the server to use a specific port.
86
+ --server-timeout SECONDS Sets the timeout that the server must start within.
87
+ -F, --[no-]fail-fast Abort after the first failing suite.
88
+
89
+ **** Filtering ****
90
+
91
+ -s, --suite SUITE Focus to a specific suite.
92
+ -g, --filter FILTER Filter tests matching a specific filter.
93
+
94
+ **** Output ****
95
+
96
+ -q, --[no-]suppress-log Suppress logs coming from console[log/debug/error].
97
+ -c, --[no-]color Enable/Disable color output.
98
+ -e, --export [OUTPUT_PATH] Exports the test suite as the full HTML (requires wget).
99
+ -f, --format FORMATTERS Specify formatters (comma separated)
100
+ dot (default) - dots
101
+ documentation - descriptive documentation
102
+ clean - like dots but doesn't log re-run commands
103
+ json - json formatter (raw teaspoon)
104
+ junit - junit compatible formatter
105
+ pride - yay rainbows!
106
+ snowday - makes you feel warm inside
107
+ swayze_or_oprah - quote from either Patrick Swayze or Oprah Winfrey
108
+ tap - test anything protocol formatter
109
+ tap_y - tap_yaml, format used by tapout
110
+ teamcity - teamcity compatible formatter
111
+
112
+ **** Coverage ****
113
+
114
+ -C, --coverage CONFIG_NAME Generate coverage reports using a pre-defined coverage configuration.
115
+
116
+ **** Utility ****
117
+
118
+ -v, --version Display the version.
119
+ -h, --help You're looking at it.
120
+ OUTPUT
121
+ end
122
+
123
+ it "has --version" do
124
+ suppress_warnings { ARGV = ["--version"] }
125
+ expect { subject.new.opt_parser }.to raise_error SystemExit
126
+ expect(@log).to match(/\d+\.\d+\.\d+\n/)
127
+ end
128
+
129
+ it "has various other arguments" do
130
+ value_flags = {
131
+ environment: ["require", "_environment_"],
132
+ driver: ["driver", "_driver_"],
133
+ driver_options: ["driver-options", "_driver_options_"],
134
+ driver_timeout: ["driver-timeout", "_driver_timeout_"],
135
+ server: ["server", "_server_"],
136
+ server_port: ["server-port", "_server_port_"],
137
+ server_timeout: ["server-timeout", "_server_timeout_"],
138
+ suite: ["suite", "_suite_"],
139
+ filter: ["filter", "_filter_"],
140
+ export: ["export", "_export_"],
141
+ formatters: ["format", "_foo,bar_"],
142
+ use_coverage: ["coverage", "_coverage_"],
143
+ }
144
+
145
+ bool_flags = {
146
+ fail_fast: "fail-fast",
147
+ suppress_log: "suppress-log",
148
+ color: "color",
149
+ }
150
+
151
+ value_flags.each do |k, v|
152
+ suppress_warnings { ARGV = ["--#{v[0]}=#{v[1]}"] }
153
+ expect(subject.new.instance_variable_get(:@options)[k]).to eq(v[1])
154
+ end
155
+
156
+ bool_flags.each do |k, v|
157
+ suppress_warnings { ARGV = ["--#{v}"] }
158
+ expect(subject.new.instance_variable_get(:@options)[k]).to eq(true)
159
+ suppress_warnings { ARGV = ["--no-#{v}"] }
160
+ expect(subject.new.instance_variable_get(:@options)[k]).to eq(false)
161
+ end
46
162
  end
47
163
 
48
164
  end
@@ -2,36 +2,38 @@ require "spec_helper"
2
2
 
3
3
  describe Teaspoon do
4
4
 
5
+ subject { Teaspoon }
6
+
5
7
  it "has a configuration property" do
6
- expect(Teaspoon.configuration).to be(Teaspoon::Configuration)
8
+ expect(subject.configuration).to be(Teaspoon::Configuration)
7
9
  end
8
10
 
9
- describe ".setup" do
11
+ describe ".configure" do
10
12
 
11
13
  it "yields configuration" do
12
14
  config = nil
13
- Teaspoon.setup { |c| config = c }
15
+ subject.configure { |c| config = c }
14
16
  expect(config).to be(Teaspoon::Configuration)
15
17
  end
16
18
 
17
- end
18
-
19
- describe ".override_from_env" do
19
+ it "sets configured to true" do
20
+ subject.configured = false
21
+ subject.configure { }
22
+ expect(subject.configured).to be_true
23
+ end
20
24
 
21
- after do
22
- ENV["SUPPRESS_LOG"] = nil
23
- ENV["FAIL_FAST"] = nil
24
- ENV["FORMATTERS"] = nil
25
+ it "overrides configuration from ENV" do
26
+ subject.configuration.should_receive(:override_from_env).with(ENV)
27
+ subject.configure { }
25
28
  end
26
29
 
27
- it "allows overriding of fail_fast and suppress_log from the env" do
28
- ENV["SUPPRESS_LOG"] = "true"
29
- ENV["FAIL_FAST"] = "false"
30
- ENV["FORMATTERS"] = "something"
31
- Teaspoon.configuration.should_receive(:suppress_log=).with(true)
32
- Teaspoon.configuration.should_receive(:fail_fast=).with(false)
33
- Teaspoon.configuration.should_receive(:formatters=).with("something")
34
- Teaspoon.send(:override_from_env)
30
+ end
31
+
32
+ describe ".setup" do
33
+
34
+ it "calls configure" do
35
+ subject.should_receive(:configure).with(&block = proc{})
36
+ subject.setup(&block)
35
37
  end
36
38
 
37
39
  end
@@ -43,68 +45,184 @@ describe Teaspoon::Configuration do
43
45
 
44
46
  subject { Teaspoon::Configuration }
45
47
 
48
+ before do
49
+ @orig_root = subject.root
50
+ @orig_asset_paths = subject.asset_paths
51
+ @orig_formatters = subject.formatters
52
+ end
53
+
46
54
  after do
47
- Teaspoon::Configuration.mount_at = "/teaspoon"
48
- Teaspoon::Configuration.suites.delete("test_suite")
49
- Teaspoon::Configuration.server = nil
55
+ subject.mount_at = "/teaspoon"
56
+ subject.suite_configs.delete("test_suite")
57
+ subject.server = nil
58
+ subject.root = @orig_root
59
+ subject.asset_paths = @orig_asset_paths
60
+ subject.formatters = @orig_formatters
50
61
  end
51
62
 
52
63
  it "has the default configuration" do
53
64
  expect(subject.mount_at).to eq("/teaspoon")
54
- expect(subject.context).to eq(nil)
65
+ expect(subject.root).to eq(Rails.root.join('..', '..'))
55
66
  expect(subject.asset_paths).to include("spec/javascripts")
56
67
  expect(subject.asset_paths).to include("spec/javascripts/stylesheets")
57
- expect(subject.fixture_path).to eq("spec/javascripts/fixtures")
58
- expect(subject.formatters).to eq(['dot'])
59
- expect(subject.server_timeout).to eq(20)
60
- expect(subject.fail_fast).to eq(true)
61
- expect(subject.suppress_log).to eq(false)
62
- expect(subject.suites).to be_a(Hash)
63
- expect(subject.coverage).to eq(false)
64
- expect(subject.coverage_reports).to eq(["text-summary"])
65
- expect(subject.coverage_output_dir).to eq("coverage")
68
+ expect(subject.fixture_paths).to eq(["spec/javascripts/fixtures", "test/javascripts/fixtures"])
69
+
70
+ expect(subject.driver).to eq("phantomjs")
71
+ expect(subject.driver_options).to be_nil
72
+ expect(subject.driver_timeout).to eq(180)
66
73
  expect(subject.server).to be_nil
67
- expect(subject.statements_coverage_threshold).to be_nil
68
- expect(subject.functions_coverage_threshold).to be_nil
69
- expect(subject.branches_coverage_threshold).to be_nil
70
- expect(subject.lines_coverage_threshold).to be_nil
74
+ expect(subject.server_port).to be_nil
75
+ expect(subject.server_timeout).to eq(20)
76
+ expect(subject.formatters).to eq(['dot'])
77
+ expect(subject.use_coverage).to be_nil
78
+ expect(subject.fail_fast).to be_true
79
+ expect(subject.suppress_log).to be_false
80
+ expect(subject.color).to be_true
81
+
82
+ expect(subject.suite_configs).to be_a(Hash)
83
+ expect(subject.coverage_configs).to be_a(Hash)
71
84
  end
72
85
 
73
86
  it "allows setting various configuration options" do
74
- Teaspoon.configuration.mount_at = "/teaspoons_are_awesome"
87
+ subject.mount_at = "/teaspoons_are_awesome"
75
88
  expect(subject.mount_at).to eq("/teaspoons_are_awesome")
76
- Teaspoon.configuration.server = :webrick
89
+ subject.server = :webrick
77
90
  expect(subject.server).to eq(:webrick)
78
91
  end
79
92
 
80
- it "allows defining suites" do
93
+ it "allows defining suite configurations" do
81
94
  subject.suite(:test_suite) { }
82
- expect(subject.suites["test_suite"]).to be_a(Proc)
95
+ expect(subject.suite_configs["test_suite"][:block]).to be_a(Proc)
96
+ expect(subject.suite_configs["test_suite"][:instance]).to be_a(Teaspoon::Configuration::Suite)
97
+ end
98
+
99
+ it "allows defining coverage configurations" do
100
+ subject.coverage(:test_coverage) { }
101
+ expect(subject.coverage_configs["test_coverage"][:block]).to be_a(Proc)
102
+ expect(subject.coverage_configs["test_coverage"][:instance]).to be_a(Teaspoon::Configuration::Coverage)
103
+ end
104
+
105
+ describe ".root=" do
106
+
107
+ it "forces the path provided into a Pathname" do
108
+ subject.root = "/path"
109
+ expect(subject.root).to be_a(Pathname)
110
+ end
111
+
112
+ end
113
+
114
+ describe ".formatters" do
115
+
116
+ it "returns the default dot formatter if nothing was set" do
117
+ expect(subject.formatters).to eq(["dot"])
118
+ end
119
+
120
+ it "returns an array of formatters if they were comma separated" do
121
+ subject.formatters = "dot,swayze_or_oprah"
122
+ expect(subject.formatters).to eq(["dot", "swayze_or_oprah"])
123
+ end
124
+
125
+ end
126
+
127
+ describe ".override_from_options" do
128
+
129
+ it "allows overriding from options" do
130
+ subject.should_receive(:fail_fast=).with(true)
131
+ subject.should_receive(:driver_timeout=).with(123)
132
+ subject.should_receive(:driver=).with("driver")
133
+
134
+ subject.send(:override_from_options, fail_fast: true, driver_timeout: 123, driver: "driver")
135
+ end
136
+
137
+ end
138
+
139
+ describe ".override_from_env" do
140
+
141
+ it "allows overriding from the env" do
142
+ subject.should_receive(:fail_fast=).with(true)
143
+ subject.should_receive(:driver_timeout=).with(123)
144
+ subject.should_receive(:driver=).with("driver")
145
+
146
+ subject.send(:override_from_env, "FAIL_FAST" => "true", "DRIVER_TIMEOUT" => "123", "DRIVER" => "driver")
147
+ end
148
+
83
149
  end
150
+
84
151
  end
85
152
 
86
153
 
87
154
  describe Teaspoon::Configuration::Suite do
88
155
 
156
+ subject { Teaspoon::Configuration::Suite.new &(@suite || proc{}) }
157
+
89
158
  it "has the default configuration" do
90
- subject = Teaspoon::Configuration::Suite.new
91
159
  expect(subject.matcher).to eq("{spec/javascripts,spec/dummy/app/assets/javascripts/specs}/**/*_spec.{js,js.coffee,coffee,js.coffee.erb}")
92
160
  expect(subject.helper).to eq("spec_helper")
93
- expect(subject.javascripts).to eq(["teaspoon/jasmine"])
161
+ expect(subject.javascripts).to eq(["jasmine/1.3.1", "teaspoon/jasmine"])
94
162
  expect(subject.stylesheets).to eq(["teaspoon"])
163
+ expect(subject.no_coverage).to eq([%r{/lib/ruby/gems/}, %r{/vendor/assets/}, %r{/support/}, %r{/(.+)_helper.}])
95
164
  end
96
165
 
97
166
  it "accepts a block that can override defaults" do
98
- subject = Teaspoon::Configuration::Suite.new { |s| s.helper = "helper_file" }
167
+ @suite = proc{ |s| s.helper = "helper_file" }
99
168
  expect(subject.helper).to eq("helper_file")
100
169
  end
101
170
 
102
-
103
- it "allows creating hooks" do
171
+ it "allows registering hooks" do
104
172
  expect(subject.hooks).to eq({})
105
-
106
173
  subject.hook {}
107
-
108
174
  expect(subject.hooks['default'].length).to eq(1)
109
175
  end
176
+
177
+ describe "specifying a framework" do
178
+
179
+ it "allows specifying mocha with a version" do
180
+ @suite = proc{ |s| s.use_framework :mocha, "1.10.0" }
181
+ expect(subject.javascripts).to eq(["mocha/1.10.0", "teaspoon-mocha"])
182
+ end
183
+
184
+ it "handles qunit specifically to set matcher and helper" do
185
+ @suite = proc{ |s| s.use_framework :qunit }
186
+ expect(subject.javascripts).to eq(["qunit/1.14.0", "teaspoon-qunit"])
187
+ expect(subject.matcher).to eq("{test/javascripts,app/assets}/**/*_test.{js,js.coffee,coffee}")
188
+ expect(subject.helper).to eq("test_helper")
189
+ end
190
+
191
+ describe "exceptions" do
192
+
193
+ it "shows an error for unknown frameworks" do
194
+ @suite = proc{ |s| s.use_framework :foo }
195
+ expect{ subject }.to raise_error Teaspoon::UnknownFramework, "Unknown framework \"foo\""
196
+ end
197
+
198
+ it "shows an error for unknown versions" do
199
+ @suite = proc{ |s| s.use_framework :qunit, "666" }
200
+ expect{ subject }.to raise_error Teaspoon::UnknownFramework, "Unknown framework \"qunit\" with version 666 -- available versions 1.12.0, 1.14.0"
201
+ end
202
+
203
+ end
204
+
205
+ end
206
+
207
+ end
208
+
209
+
210
+ describe Teaspoon::Configuration::Coverage do
211
+
212
+ subject { Teaspoon::Configuration::Coverage.new &(@coverage || proc{}) }
213
+
214
+ it "has the default configuration" do
215
+ expect(subject.reports).to eq(["text-summary"])
216
+ expect(subject.output_path).to eq("coverage")
217
+ expect(subject.statements).to be_nil
218
+ expect(subject.functions).to be_nil
219
+ expect(subject.branches).to be_nil
220
+ expect(subject.lines).to be_nil
221
+ end
222
+
223
+ it "accepts a block that can override defaults" do
224
+ @coverage = proc{ |s| s.reports = "report_format" }
225
+ expect(subject.reports).to eq("report_format")
226
+ end
227
+
110
228
  end