protest 0.2.1 → 0.2.2
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.
- data/README.rdoc +1 -1
- data/lib/protest/report.rb +9 -1
- data/lib/protest/runner.rb +8 -11
- data/lib/protest/test_case.rb +35 -15
- data/protest.gemspec +2 -2
- metadata +2 -2
    
        data/README.rdoc
    CHANGED
    
    
    
        data/lib/protest/report.rb
    CHANGED
    
    | @@ -36,6 +36,10 @@ module Protest | |
| 36 36 | 
             
                  end
         | 
| 37 37 | 
             
                end
         | 
| 38 38 |  | 
| 39 | 
            +
                on :test do |report, test|
         | 
| 40 | 
            +
                  report.tests << test
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 39 43 | 
             
                on :start do |report|
         | 
| 40 44 | 
             
                  report.instance_eval { @started_at = Time.now }
         | 
| 41 45 | 
             
                end
         | 
| @@ -100,9 +104,13 @@ module Protest | |
| 100 104 | 
             
                  @assertions || 0
         | 
| 101 105 | 
             
                end
         | 
| 102 106 |  | 
| 107 | 
            +
                def tests
         | 
| 108 | 
            +
                  @tests ||= []
         | 
| 109 | 
            +
                end
         | 
| 110 | 
            +
             | 
| 103 111 | 
             
                # Amount ot tests run (whether passed, pending, failed, or errored.)
         | 
| 104 112 | 
             
                def total_tests
         | 
| 105 | 
            -
                   | 
| 113 | 
            +
                  tests.size
         | 
| 106 114 | 
             
                end
         | 
| 107 115 |  | 
| 108 116 | 
             
                # Seconds taken since the test suite started running
         | 
    
        data/lib/protest/runner.rb
    CHANGED
    
    | @@ -20,23 +20,20 @@ module Protest | |
| 20 20 | 
             
                end
         | 
| 21 21 |  | 
| 22 22 | 
             
                # Run a test and report if it passes, fails, or is pending. Takes the name
         | 
| 23 | 
            -
                # of the test as an argument.  | 
| 24 | 
            -
                #  | 
| 25 | 
            -
                 | 
| 26 | 
            -
             | 
| 27 | 
            -
                   | 
| 28 | 
            -
                  @report | 
| 23 | 
            +
                # of the test as an argument. By passing +true+ as the second argument, you
         | 
| 24 | 
            +
                # force any exceptions to be re-raied and the test not reported as a pass
         | 
| 25 | 
            +
                # after it finishes (for global setup/teardown blocks)
         | 
| 26 | 
            +
                def report(test, running_global_setup_or_teardown=false)
         | 
| 27 | 
            +
                  @report.on_test(Test.new(test)) if @report.respond_to?(:on_test) && !running_global_setup_or_teardown
         | 
| 28 | 
            +
                  test.run(@report)
         | 
| 29 | 
            +
                  @report.on_pass(PassedTest.new(test)) unless running_global_setup_or_teardown
         | 
| 29 30 | 
             
                rescue Pending => e
         | 
| 30 31 | 
             
                  @report.on_pending(PendingTest.new(test, e))
         | 
| 31 32 | 
             
                rescue AssertionFailed => e
         | 
| 32 33 | 
             
                  @report.on_failure(FailedTest.new(test, e))
         | 
| 33 34 | 
             
                rescue Exception => e
         | 
| 34 35 | 
             
                  @report.on_error(ErroredTest.new(test, e))
         | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
                def assert(condition, message) #:nodoc:
         | 
| 38 | 
            -
                  @report.add_assertion
         | 
| 39 | 
            -
                  raise AssertionFailed, message unless condition
         | 
| 36 | 
            +
                  raise if running_global_setup_or_teardown
         | 
| 40 37 | 
             
                end
         | 
| 41 38 | 
             
              end
         | 
| 42 39 | 
             
            end
         | 
    
        data/lib/protest/test_case.rb
    CHANGED
    
    | @@ -27,10 +27,15 @@ module Protest | |
| 27 27 | 
             
              class TestCase
         | 
| 28 28 | 
             
                # Run all tests in this context. Takes a Report instance in order to
         | 
| 29 29 | 
             
                # provide output.
         | 
| 30 | 
            -
                def self.run( | 
| 31 | 
            -
                   | 
| 32 | 
            -
                  tests.each {|test|  | 
| 33 | 
            -
                   | 
| 30 | 
            +
                def self.run(runner)
         | 
| 31 | 
            +
                  runner.report(TestWrapper.new(:setup, self), true)
         | 
| 32 | 
            +
                  tests.each {|test| runner.report(test, false) }
         | 
| 33 | 
            +
                  runner.report(TestWrapper.new(:teardown, self), true)
         | 
| 34 | 
            +
                rescue Exception => e
         | 
| 35 | 
            +
                  # If any exception bubbles up here, then it means it was during the
         | 
| 36 | 
            +
                  # global setup/teardown blocks, so let's just skip the rest of this
         | 
| 37 | 
            +
                  # context.
         | 
| 38 | 
            +
                  return
         | 
| 34 39 | 
             
                end
         | 
| 35 40 |  | 
| 36 41 | 
             
                # Tests added to this context.
         | 
| @@ -104,7 +109,6 @@ module Protest | |
| 104 109 | 
             
                  end
         | 
| 105 110 | 
             
                end
         | 
| 106 111 |  | 
| 107 | 
            -
             | 
| 108 112 | 
             
                # Define a new test context nested under the current one. All +setup+ and
         | 
| 109 113 | 
             
                # +teardown+ blocks defined on the current context will be inherited by the
         | 
| 110 114 | 
             
                # new context. This method is aliased as +describe+ for your comfort.
         | 
| @@ -148,23 +152,22 @@ module Protest | |
| 148 152 | 
             
                #
         | 
| 149 153 | 
             
                # If the test's block is nil, then the test will be marked as pending and
         | 
| 150 154 | 
             
                # nothing will be run.
         | 
| 151 | 
            -
                def run( | 
| 152 | 
            -
                  @ | 
| 153 | 
            -
             | 
| 154 | 
            -
                  runner.report(self) do
         | 
| 155 | 
            -
                    pending if test.nil?
         | 
| 155 | 
            +
                def run(report)
         | 
| 156 | 
            +
                  @report = report
         | 
| 157 | 
            +
                  pending if test.nil?
         | 
| 156 158 |  | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
                   | 
| 159 | 
            +
                  setup
         | 
| 160 | 
            +
                  instance_eval(&test)
         | 
| 161 | 
            +
                  teardown
         | 
| 162 | 
            +
                  @report = nil
         | 
| 161 163 | 
             
                end
         | 
| 162 164 |  | 
| 163 165 | 
             
                # Ensure a condition is met. This will raise AssertionFailed if the
         | 
| 164 166 | 
             
                # condition isn't met. You can override the default failure message
         | 
| 165 167 | 
             
                # by passing it as an argument.
         | 
| 166 168 | 
             
                def assert(condition, message="Expected condition to be satisfied")
         | 
| 167 | 
            -
                  @ | 
| 169 | 
            +
                  @report.add_assertion
         | 
| 170 | 
            +
                  raise AssertionFailed, message unless condition
         | 
| 168 171 | 
             
                end
         | 
| 169 172 |  | 
| 170 173 | 
             
                # Provided for Test::Unit compatibility, this lets you include
         | 
| @@ -217,5 +220,22 @@ module Protest | |
| 217 220 | 
             
                def self.inherited(child)
         | 
| 218 221 | 
             
                  Protest.add_test_case(child)
         | 
| 219 222 | 
             
                end
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                # Provides the TestCase API for global setup/teardown blocks, so they can be
         | 
| 225 | 
            +
                # "faked" as tests into the reporter (they aren't counted towards the total
         | 
| 226 | 
            +
                # number of tests but they could count towards the number of failures/errors.)
         | 
| 227 | 
            +
                class TestWrapper #:nodoc:
         | 
| 228 | 
            +
                  attr_reader :name
         | 
| 229 | 
            +
             | 
| 230 | 
            +
                  def initialize(type, test_case)
         | 
| 231 | 
            +
                    @type = type
         | 
| 232 | 
            +
                    @test = test_case
         | 
| 233 | 
            +
                    @name = "Global #{@type} for #{test_case.description}"
         | 
| 234 | 
            +
                  end
         | 
| 235 | 
            +
             | 
| 236 | 
            +
                  def run(report)
         | 
| 237 | 
            +
                    @test.send("do_global_#{@type}")
         | 
| 238 | 
            +
                  end
         | 
| 239 | 
            +
                end
         | 
| 220 240 | 
             
              end
         | 
| 221 241 | 
             
            end
         | 
    
        data/protest.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: protest
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - "Nicol\xC3\xA1s Sanguinetti"
         | 
| @@ -9,7 +9,7 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2009-09- | 
| 12 | 
            +
            date: 2009-09-17 00:00:00 -03:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: []
         | 
| 15 15 |  |