baretest 0.2.4 → 0.4.0.pre1

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 (85) hide show
  1. data/LICENSE.txt +6 -6
  2. data/MANIFEST.txt +40 -18
  3. data/README.rdoc +8 -1
  4. data/bin/baretest +126 -118
  5. data/doc/baretest.rdoc +1 -1
  6. data/doc/mocking_stubbing_test_doubles.rdoc +31 -3
  7. data/doc/news/news-0.3.0.rdoc +7 -0
  8. data/doc/quickref.rdoc +74 -28
  9. data/doc/whats_going_on.rdoc +5 -0
  10. data/doc/writing_tests.rdoc +25 -13
  11. data/examples/components/rack-test.rb +17 -0
  12. data/examples/{tests/irb_mode → irb_mode}/failures.rb +0 -0
  13. data/examples/rake/test.rake +40 -0
  14. data/examples/tests/01_basics_I.rb +34 -0
  15. data/examples/tests/02_basics_II_helpers.rb +25 -0
  16. data/examples/tests/03_basics_III_setup_and_teardown.rb +53 -0
  17. data/examples/tests/04_advanced_I_dependencies.rb +31 -0
  18. data/examples/tests/05_advanced_II_tags.rb +12 -0
  19. data/examples/tests/06_advanced_III_requires.rb +21 -0
  20. data/examples/tests/07_advanced_IV_components.rb +48 -0
  21. data/examples/tests/08_expert_I_setup_variants.rb +46 -0
  22. data/lib/baretest.rb +142 -21
  23. data/lib/baretest/assertion.rb +83 -92
  24. data/lib/baretest/assertion/context.rb +9 -0
  25. data/lib/baretest/assertion/support.rb +88 -61
  26. data/lib/baretest/commandline.rb +268 -0
  27. data/lib/baretest/formatter.rb +58 -0
  28. data/lib/baretest/invalidselectors.rb +24 -0
  29. data/lib/baretest/irb_mode.rb +100 -58
  30. data/lib/baretest/persistence.rb +94 -0
  31. data/lib/baretest/run.rb +138 -37
  32. data/lib/baretest/run/cli.rb +97 -43
  33. data/lib/baretest/run/minimal.rb +2 -1
  34. data/lib/baretest/run/none.rb +21 -0
  35. data/lib/baretest/run/xml.rb +21 -19
  36. data/lib/baretest/setup.rb +2 -0
  37. data/lib/baretest/status.rb +93 -0
  38. data/lib/baretest/suite.rb +185 -59
  39. data/lib/baretest/uid.rb +51 -0
  40. data/lib/baretest/use/mocha.rb +24 -0
  41. data/lib/baretest/use/rack_test.rb +9 -0
  42. data/lib/baretest/use/rr.rb +17 -0
  43. data/lib/baretest/version.rb +18 -4
  44. data/lib/command.rb +36 -0
  45. data/lib/command/argument.rb +11 -0
  46. data/lib/command/decoratinghash.rb +31 -0
  47. data/lib/command/definition.rb +294 -0
  48. data/lib/command/directorynotfounderror.rb +11 -0
  49. data/lib/command/env.rb +11 -0
  50. data/lib/command/filenotfounderror.rb +11 -0
  51. data/lib/command/kernel.rb +14 -0
  52. data/lib/command/nodirectoryerror.rb +11 -0
  53. data/lib/command/nofileerror.rb +11 -0
  54. data/lib/command/option.rb +16 -0
  55. data/lib/command/parser.rb +145 -0
  56. data/lib/command/result.rb +11 -0
  57. data/lib/command/types.rb +33 -0
  58. data/lib/command/version.rb +28 -0
  59. data/test/setup.rb +3 -0
  60. data/test/suite/lib/baretest.rb +0 -178
  61. data/test/suite/lib/baretest/assertion.rb +133 -112
  62. data/test/suite/lib/baretest/assertion/context.rb +40 -0
  63. data/test/suite/lib/baretest/assertion/failure.rb +19 -0
  64. data/test/suite/lib/baretest/assertion/skip.rb +19 -0
  65. data/test/suite/lib/baretest/assertion/support.rb +366 -84
  66. data/test/suite/lib/baretest/run.rb +114 -15
  67. data/test/suite/lib/baretest/suite.rb +70 -29
  68. metadata +46 -24
  69. data/examples/test.rake +0 -65
  70. data/examples/tests/mock_developer/test/helper/mocks.rb +0 -0
  71. data/examples/tests/mock_developer/test/setup.rb +0 -57
  72. data/examples/tests/mock_developer/test/suite/mock_demo.rb +0 -19
  73. data/examples/tests/overview/test.rb +0 -89
  74. data/examples/tests/variations/variations_01.rb +0 -14
  75. data/examples/tests/variations/variations_02.rb +0 -19
  76. data/examples/tests/variations/variations_03.rb +0 -19
  77. data/lib/baretest/mocha.rb +0 -18
  78. data/lib/baretest/rr.rb +0 -16
  79. data/lib/baretest/run/errors.rb +0 -49
  80. data/lib/baretest/skipped.rb +0 -15
  81. data/lib/baretest/skipped/assertion.rb +0 -20
  82. data/lib/baretest/skipped/suite.rb +0 -49
  83. data/test/external/bootstraptest.rb +0 -5
  84. data/test/external/bootstrapwrap.rb +0 -2
  85. data/test/helper/mocks.rb +0 -0
data/examples/test.rake DELETED
@@ -1,65 +0,0 @@
1
- #--
2
- # Copyright 2009-2010 by Stefan Rusterholz.
3
- # All rights reserved.
4
- # See LICENSE.txt for permissions.
5
- #++
6
-
7
-
8
-
9
- # This rake task expects to be in PROJECT_DIR/tasks/test.rake
10
- # It assumes that the tests are in PROJECT_DIR/test/**/*.rb
11
- # This is relevant as it calculates the paths accordingly.
12
- # It uses BareTest.load_standard_test_files to load setup and test files.
13
- # This means it will also load a test/setup.rb file if present, where
14
- # you can add paths to $LOAD_PATH.
15
-
16
- namespace :test do
17
- desc "Information about how your test directory should look."
18
- task :structure do
19
- wd = File.expand_path(Dir.getwd)
20
- rake_file = File.expand_path(__FILE__)
21
- test_dir = ['./test', "#{rake_file}/../../test"].map { |path|
22
- full = File.expand_path(path)
23
- relative = full[(wd.size+1)..-1]
24
- "* #{relative} (#{full})"
25
- }
26
-
27
- puts "rake test:run expects to find one of the these directories:", *test_dir
28
- end
29
-
30
- desc "Run testsuite. Set FORMAT env variable to change the formatter used, INTERACTIVE to have irb mode."
31
- task :run do
32
- begin
33
- require 'baretest'
34
- rescue LoadError => e
35
- puts "Could not run tests: #{e}"
36
- else
37
- # Prepare paths
38
- rake_file = File.expand_path(__FILE__)
39
- test_dir = ["#{rake_file}/../../test", './test'].map { |path|
40
- File.expand_path(path)
41
- }.find { |path|
42
- File.directory?(path)
43
- }
44
-
45
- # Verify that the test directory exists
46
- raise "Could not determine test directory, please adapt this rake task to " \
47
- "your directory structure first (see rake test:structure)." unless test_dir
48
-
49
- # Load all test definitions
50
- BareTest.load_standard_test_files(
51
- :verbose => $VERBOSE,
52
- :setup_file => 'test/setup.rb',
53
- :chdir => File.dirname(test_dir) # must chdir to 1 above the 'test' dir
54
- )
55
-
56
- # Run all tests
57
- format = ENV["FORMAT"] || 'cli'
58
- interactive = ENV["INTERACTIVE"] == 'true'
59
- BareTest.run(:format => format, :interactive => interactive)
60
- end
61
- end
62
- end
63
-
64
- desc 'Alias for test:run'
65
- task :test => 'test:run'
File without changes
@@ -1,57 +0,0 @@
1
- $LOAD_PATH.unshift(File.expand_path("#{__FILE__}/../../lib"))
2
- require 'baretest'
3
-
4
- BareTest.toplevel_suite.setup do
5
- @_mymockname = {
6
- :mocks => [],
7
- :failures => [],
8
- :exceptions => []
9
- }
10
- end
11
- BareTest.toplevel_suite.teardown do
12
- @_mymockname[:mocks].each { |mock|
13
- mock.teardown(@_mymockname)
14
- }
15
- unless @_mymockname[:exceptions].empty? then
16
- @reason = "An error occurred"
17
- @exception = @_mymockname[:exceptions].first
18
- @status = :error
19
- end
20
- unless @status == :error || @_mymockname[:failures].empty?
21
- @reason = @_mymockname[:failures].first
22
- @status = :failure
23
- end
24
- end
25
-
26
- class DemoMock
27
- class Error < StandardError; end
28
-
29
- def initialize(action, message)
30
- @action, @message = action, message
31
- end
32
-
33
- def teardown(recorder)
34
- case @action
35
- when :fail
36
- recorder[:failures] << @message
37
- when :raise
38
- raise @message
39
- end
40
- rescue Error => e
41
- recorder[:exceptions] << e
42
- end
43
- end
44
-
45
- module MockSupport
46
- def demo_mock(*args, &block)
47
- mock = DemoMock.new(*args, &block)
48
- @_mymockname[:mocks] << mock
49
- mock
50
- end
51
- end
52
-
53
- module BareTest
54
- class Assertion
55
- include MockSupport
56
- end
57
- end
@@ -1,19 +0,0 @@
1
- BareTest.suite "MockDemo" do
2
- suite "nothing happens" do
3
- assert "Success" do
4
- demo_mock(nil, nil)
5
- end
6
- end
7
-
8
- suite "mock fails" do
9
- assert "Failure" do
10
- demo_mock(:fail, "this is the mock failure message")
11
- end
12
- end
13
-
14
- suite "mock errors" do
15
- assert "Exception" do
16
- demo_mock(:raise, DemoMock::Error.new("mock errors message"))
17
- end
18
- end
19
- end
@@ -1,89 +0,0 @@
1
- BareTest.suite do
2
- # assertions and refutations can be grouped in suites. They will share
3
- # setup and teardown
4
- # they don't have to be in suites, though
5
- suite "Success" do
6
- assert "An assertion returning a trueish value (non nil/false) is a success" do
7
- true
8
- end
9
- end
10
-
11
- suite "Failure" do
12
- assert "An assertion returning a falsish value (nil/false) is a failure" do
13
- false
14
- end
15
- end
16
-
17
- suite "Pending" do
18
- assert "An assertion without a block is pending"
19
- end
20
-
21
- suite "Error" do
22
- assert "Uncaught exceptions in an assertion are an error" do
23
- raise "Error!"
24
- end
25
- end
26
-
27
- suite "Special assertions" do
28
- assert "Assert a block to raise" do
29
- raises do
30
- sleep(rand()/3+0.05)
31
- raise "If this raises then the assertion is a success"
32
- end
33
- end
34
-
35
- assert "Assert a float to be close to another" do
36
- a = 0.18 - 0.01
37
- b = 0.17
38
- within_delta a, b, 0.001
39
- end
40
-
41
- suite "Nested suite" do
42
- assert "Assert two randomly ordered arrays to contain the same values" do
43
- a = [*"A".."Z"] # an array with values from A to Z
44
- b = a.sort_by { rand }
45
- equal_unordered(a, b) # can be used with any Enumerable, uses hash-key identity
46
- end
47
- end
48
- end
49
-
50
- suite "Setup & Teardown" do
51
- setup do
52
- @foo = "foo"
53
- @bar = "bar"
54
- end
55
-
56
- assert "@foo should be set" do
57
- @foo == "foo"
58
- end
59
-
60
- suite "Nested suite" do
61
- setup do
62
- @bar = "inner bar"
63
- @baz = "baz"
64
- end
65
-
66
- assert "@foo is inherited" do
67
- @foo == "foo"
68
- end
69
-
70
- assert "@bar is overridden" do
71
- @bar == "inner bar"
72
- end
73
-
74
- assert "@baz is defined only for inner" do
75
- @baz == "baz"
76
- end
77
- end
78
-
79
- teardown do
80
- @foo = nil # not that it'd make much sense, just to demonstrate
81
- end
82
- end
83
-
84
- suite "Dependencies", :requires => ['foo', 'bar'] do
85
- assert "Will be skipped, due to unsatisfied dependencies" do
86
- failure "Why the heck do you have a 'foo/bar' file?"
87
- end
88
- end
89
- end
@@ -1,14 +0,0 @@
1
- require 'pp'
2
-
3
- BareTest.suite "Variations 01" do
4
- setup do puts "n1" end
5
- setup do puts "n2" end
6
- setup :a, "a1" do puts "a1" end
7
- setup :a, "a2" do puts "a2" end
8
- setup :b, "b1" do puts "b1" end
9
- setup :b, "b2" do puts "b2" end
10
-
11
- assert "variants, a: :a, b: :b" do
12
- true
13
- end
14
- end
@@ -1,19 +0,0 @@
1
- require 'pp'
2
-
3
- class String
4
- def numeric?
5
- self =~ /[+-]?(?:[1-9]\d*|0)(?:\.\d+)?(?:[eE][+-]?\d+)?/
6
- end
7
- end
8
-
9
- BareTest.suite do
10
- suite "Variations 02" do
11
- setup :number, %w[123 -123 1.23 -1.23 1e3 -1e3 1e-3 -1e-3] do |number|
12
- @number = number
13
- end
14
-
15
- assert ":number should be a numeric" do
16
- @number.numeric?
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- require 'pp'
2
-
3
- class String
4
- def numeric?
5
- self =~ /[+-]?(?:[1-9]\d*|0)(?:\.\d+)?(?:[eE][+-]?\d+)?/
6
- end
7
- end
8
-
9
- BareTest.suite do
10
- suite "Variations 02" do
11
- setup :number, {'"123"' => "123", '"1.23"' => "1.23", '"1e3"' => "1e3"} do |number|
12
- @number = number
13
- end
14
-
15
- assert ":number should be a numeric" do
16
- @number.numeric?
17
- end
18
- end
19
- end
@@ -1,18 +0,0 @@
1
- # Created by dominikh
2
-
3
- # This file provides integration with the "mocha" mocking framework.
4
-
5
- require 'mocha'
6
-
7
- BareTest.extend Mocha::API
8
-
9
- BareTest.toplevel_suite.teardown do
10
- begin
11
- BareTest.mocha_verify
12
- rescue Mocha::ExpectationError => e
13
- @reason = e.message
14
- @status = :failure
15
- ensure
16
- BareTest.mocha_teardown
17
- end
18
- end
data/lib/baretest/rr.rb DELETED
@@ -1,16 +0,0 @@
1
- # Load this file and get integration with the "rr" mocking framework.
2
-
3
- require 'rr'
4
-
5
- class BareTest::Assertion::Context
6
- include RR::Adapters::RRMethods
7
- end
8
-
9
- BareTest.toplevel_suite.teardown do
10
- begin
11
- RR.verify
12
- rescue RR::Errors => e
13
- @reason = e.message
14
- @status = :failure
15
- end
16
- end
@@ -1,49 +0,0 @@
1
- #--
2
- # Copyright 2009-2010 by Stefan Rusterholz.
3
- # All rights reserved.
4
- # See LICENSE.txt for permissions.
5
- #++
6
-
7
-
8
-
9
- module BareTest
10
- class Run
11
-
12
- # Errors runner is invoked with `-f errors` or `--format errors`.
13
- # This runner is specifically built to provide the most possible information about
14
- # errors in the suite.
15
- #
16
- module Errors # :nodoc:
17
- def run_all
18
- @depth = 0
19
- puts "Running all tests, reporting only errors and failures"
20
- start = Time.now
21
- super
22
- stop = Time.now
23
- printf "\Ran #{@count[:test]} tests (#{@count[:pending]} pending) in %.1fs\n" \
24
- "#{@count[:failure]} failures and #{@count[:error]} errors encountered.\n",
25
- (stop-start)
26
- end
27
-
28
- def run_test(assertion, setup)
29
- rv = super # run the assertion
30
- if rv.status == :failure then
31
- head = "FAILURE in #{rv.description}"
32
- message = rv.reason || "no failure reason given"
33
- stack = "#{rv.file}:#{rv.line}"
34
- elsif rv.exception then
35
- size = caller.size+5
36
- head = "ERROR in #{rv.description}"
37
- message = rv.exception.message || "no exception message given"
38
- stack = rv.exception.backtrace[0..-size].join("\n ")
39
- else
40
- return
41
- end
42
-
43
- puts head, " "+message.gsub(/\n/, "\n "), " "+stack, ""
44
- end
45
- end
46
- end
47
-
48
- @format["baretest/run/errors"] = Run::Errors # register the extender
49
- end
@@ -1,15 +0,0 @@
1
- #--
2
- # Copyright 2009-2010 by Stefan Rusterholz.
3
- # All rights reserved.
4
- # See LICENSE.txt for permissions.
5
- #++
6
-
7
-
8
-
9
- module BareTest
10
-
11
- # Skipped contains variants of Suite and Assertion.
12
- # See Skipped::Suite and Skipped::Assertion
13
- module Skipped
14
- end
15
- end
@@ -1,20 +0,0 @@
1
- #--
2
- # Copyright 2009-2010 by Stefan Rusterholz.
3
- # All rights reserved.
4
- # See LICENSE.txt for permissions.
5
- #++
6
-
7
-
8
-
9
- module BareTest
10
- module Skipped
11
-
12
- # Like Test::Assertion, but fakes execution and sets status always to
13
- # skipped.
14
- class Assertion < ::BareTest::Assertion
15
- def execute(setup=nil) # :nodoc:
16
- @status = :skipped and self
17
- end
18
- end
19
- end
20
- end
@@ -1,49 +0,0 @@
1
- #--
2
- # Copyright 2009-2010 by Stefan Rusterholz.
3
- # All rights reserved.
4
- # See LICENSE.txt for permissions.
5
- #++
6
-
7
-
8
-
9
- require 'baretest/skipped/assertion'
10
-
11
-
12
-
13
- module BareTest
14
-
15
- module Skipped
16
-
17
- # Like Test::Suite, but all Assertions are defined as Skipped::Assertion
18
- class Suite < ::BareTest::Suite
19
- def self.create(description=nil, parent=nil, opts={}, &block) # :nodoc:
20
- new(description, parent, &block) # Skipped::Suite always
21
- end
22
-
23
- # All Assertions use Skipped::Assertion instead of Test::Assertion.
24
- def assert(description=nil, &block) # :nodoc:
25
- @skipped << Skipped::Assertion.new(self, description, &block)
26
- end
27
-
28
- # All setup blocks are disabled
29
- def ancestry_setup # :nodoc:
30
- []
31
- end
32
-
33
- # All teardown blocks are disabled
34
- def ancestry_teardown # :nodoc:
35
- []
36
- end
37
-
38
- # All setup blocks are disabled
39
- def setup(&block) # :nodoc:
40
- []
41
- end
42
-
43
- # All teardown blocks are disabled
44
- def teardown(&block) # :nodoc:
45
- []
46
- end
47
- end
48
- end
49
- end