opal-spec 0.2.10 → 0.2.11
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/CHANGELOG.md +26 -0
- data/Gemfile +0 -2
- data/README.md +9 -32
- data/lib/assets/javascripts/opal/spec.rb +3 -3
- data/lib/assets/javascripts/opal/spec/browser_formatter.rb +1 -1
- data/lib/assets/javascripts/opal/spec/expectations.rb +11 -12
- data/lib/assets/javascripts/opal/spec/kernel.rb +6 -1
- data/lib/assets/javascripts/opal/spec/matchers.rb +2 -2
- data/lib/assets/javascripts/opal/spec/phantom_formatter.rb +1 -1
- data/lib/assets/javascripts/opal/spec/runner.rb +2 -2
- data/lib/assets/javascripts/opal/spec/spec.rb +86 -0
- data/lib/assets/javascripts/opal/spec/sprockets_runner.rb.erb +1 -1
- data/lib/assets/javascripts/opal/spec/test_case.rb +120 -0
- data/lib/opal/spec/version.rb +1 -1
- data/opal-spec.gemspec +2 -0
- data/spec/specs.rb +42 -24
- data/spec/tests.rb +9 -0
- metadata +23 -5
- data/lib/assets/javascripts/opal/spec/example.rb +0 -76
- data/lib/assets/javascripts/opal/spec/example_group.rb +0 -92
    
        data/CHANGELOG.md
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            ## 0.2.11 2013-02-20
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            *   Added TestCase class to allow unit tests. OpalTest::Spec now inherits from
         | 
| 4 | 
            +
                OpalTest::TestCase.
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            *   Added Spec#let and Spec#subject.
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## 0.2.7
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            *   Can be built using asset pipeline/sprockets.
         | 
| 11 | 
            +
            *   BrowserFormatter is now default.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## 0.0.3
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            *   Allow group names to be non-strings.
         | 
| 16 | 
            +
            *   Nested groups now have outer group name as prefix.
         | 
| 17 | 
            +
            *   Nested groups should inherit `before` and `after` blocks.
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## 0.0.2
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            *   Added seperate BrowserFormatter class for cleaner output.
         | 
| 22 | 
            +
            *   Update Rake tasks to use new Opal::Builder class.
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ## 0.0.1
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            *   Initial Release.
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -38,17 +38,17 @@ Opal::Spec::Runner.autorun | |
| 38 38 | 
             
            Examples can be async, and need to be defined as so:
         | 
| 39 39 |  | 
| 40 40 | 
             
            ```ruby
         | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 41 | 
            +
            describe 'MyClass' do
         | 
| 42 | 
            +
              # normal, sync example
         | 
| 43 | 
            +
              it 'does something' do
         | 
| 44 | 
            +
                #...
         | 
| 45 | 
            +
              end
         | 
| 46 46 |  | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
                end
         | 
| 47 | 
            +
              # async example
         | 
| 48 | 
            +
              async 'does something else too' do
         | 
| 49 | 
            +
                #...
         | 
| 51 50 | 
             
              end
         | 
| 51 | 
            +
            end
         | 
| 52 52 | 
             
            ```
         | 
| 53 53 |  | 
| 54 54 | 
             
            This just marks the example as being async. To actually handle the async
         | 
| @@ -66,26 +66,3 @@ end | |
| 66 66 |  | 
| 67 67 | 
             
            The end of the block passed to `run_async` informs opal-spec that you are
         | 
| 68 68 | 
             
            done with this test, so it can move on.
         | 
| 69 | 
            -
             | 
| 70 | 
            -
            Change Log
         | 
| 71 | 
            -
            ----------
         | 
| 72 | 
            -
             | 
| 73 | 
            -
            ### 0.2.7
         | 
| 74 | 
            -
             | 
| 75 | 
            -
            * Can be built using asset pipeline/sprockets
         | 
| 76 | 
            -
            * BrowserFormatter is now default
         | 
| 77 | 
            -
             | 
| 78 | 
            -
            ### 0.0.3
         | 
| 79 | 
            -
             | 
| 80 | 
            -
            * Allow group names to be non-strings
         | 
| 81 | 
            -
            * Nested groups now have outer group name as prefix
         | 
| 82 | 
            -
            * Nested groups should inherit `before` and `after` blocks
         | 
| 83 | 
            -
             | 
| 84 | 
            -
            ### 0.0.2
         | 
| 85 | 
            -
             | 
| 86 | 
            -
            * Added seperate BrowserFormatter class for cleaner output
         | 
| 87 | 
            -
            * Update Rake tasks to use new Opal::Builder class
         | 
| 88 | 
            -
             | 
| 89 | 
            -
            ### 0.0.1
         | 
| 90 | 
            -
             | 
| 91 | 
            -
            Initial release
         | 
| @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            require 'opal'
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'opal/spec/ | 
| 4 | 
            -
            require 'opal/spec/ | 
| 3 | 
            +
            require 'opal/spec/test_case'
         | 
| 4 | 
            +
            require 'opal/spec/spec'
         | 
| 5 5 | 
             
            require 'opal/spec/matchers'
         | 
| 6 6 | 
             
            require 'opal/spec/runner'
         | 
| 7 7 | 
             
            require 'opal/spec/scratch_pad'
         | 
| @@ -11,5 +11,5 @@ require 'opal/spec/phantom_formatter' | |
| 11 11 | 
             
            require 'opal/spec/kernel'
         | 
| 12 12 |  | 
| 13 13 | 
             
            module Opal
         | 
| 14 | 
            -
              Spec = :: | 
| 14 | 
            +
              Spec = ::OpalTest # compatibility
         | 
| 15 15 | 
             
            end
         | 
| @@ -1,5 +1,4 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
            module Spec
         | 
| 1 | 
            +
            module OpalTest
         | 
| 3 2 | 
             
              class ExpectationNotMetError < StandardError; end
         | 
| 4 3 |  | 
| 5 4 | 
             
              module Expectations
         | 
| @@ -7,7 +6,7 @@ module Spec | |
| 7 6 | 
             
                  if matcher
         | 
| 8 7 | 
             
                    matcher.match self
         | 
| 9 8 | 
             
                  else
         | 
| 10 | 
            -
                     | 
| 9 | 
            +
                    PositiveOperatorMatcher.new self
         | 
| 11 10 | 
             
                  end
         | 
| 12 11 | 
             
                end
         | 
| 13 12 |  | 
| @@ -15,40 +14,40 @@ module Spec | |
| 15 14 | 
             
                  if matcher
         | 
| 16 15 | 
             
                    matcher.not_match self
         | 
| 17 16 | 
             
                  else
         | 
| 18 | 
            -
                     | 
| 17 | 
            +
                    NegativeOperatorMatcher.new self
         | 
| 19 18 | 
             
                  end
         | 
| 20 19 | 
             
                end
         | 
| 21 20 |  | 
| 22 21 | 
             
                def be_kind_of expected
         | 
| 23 | 
            -
                   | 
| 22 | 
            +
                  BeKindOfMatcher.new expected
         | 
| 24 23 | 
             
                end
         | 
| 25 24 |  | 
| 26 25 | 
             
                def be_nil
         | 
| 27 | 
            -
                   | 
| 26 | 
            +
                  BeNilMatcher.new nil
         | 
| 28 27 | 
             
                end
         | 
| 29 28 |  | 
| 30 29 | 
             
                def be_true
         | 
| 31 | 
            -
                   | 
| 30 | 
            +
                  BeTrueMatcher.new true
         | 
| 32 31 | 
             
                end
         | 
| 33 32 |  | 
| 34 33 | 
             
                def be_false
         | 
| 35 | 
            -
                   | 
| 34 | 
            +
                  BeFalseMatcher.new false
         | 
| 36 35 | 
             
                end
         | 
| 37 36 |  | 
| 38 37 | 
             
                def eq(expected)
         | 
| 39 | 
            -
                   | 
| 38 | 
            +
                  EqlMatcher.new expected
         | 
| 40 39 | 
             
                end
         | 
| 41 40 |  | 
| 42 41 | 
             
                def equal expected
         | 
| 43 | 
            -
                   | 
| 42 | 
            +
                  EqualMatcher.new expected
         | 
| 44 43 | 
             
                end
         | 
| 45 44 |  | 
| 46 45 | 
             
                def raise_error expected
         | 
| 47 | 
            -
                   | 
| 46 | 
            +
                  RaiseErrorMatcher.new expected
         | 
| 48 47 | 
             
                end
         | 
| 49 48 | 
             
              end
         | 
| 50 49 | 
             
            end
         | 
| 51 50 |  | 
| 52 51 | 
             
            class Object
         | 
| 53 | 
            -
              include  | 
| 52 | 
            +
              include OpalTest::Expectations
         | 
| 54 53 | 
             
            end
         | 
| @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            module  | 
| 1 | 
            +
            module OpalTest
         | 
| 2 2 | 
             
              class Matcher
         | 
| 3 3 | 
             
                def initialize(actual)
         | 
| 4 4 | 
             
                  @actual = actual
         | 
| @@ -62,7 +62,7 @@ module Spec | |
| 62 62 | 
             
              class EqlMatcher < Matcher
         | 
| 63 63 | 
             
                def match(expected)
         | 
| 64 64 | 
             
                  unless expected == @actual
         | 
| 65 | 
            -
                    failure "expected: #{ | 
| 65 | 
            +
                    failure "expected: #{@actual.inspect}, got: #{expected.inspect} (using ==)."
         | 
| 66 66 | 
             
                  end
         | 
| 67 67 | 
             
                end
         | 
| 68 68 |  | 
| @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            module  | 
| 1 | 
            +
            module OpalTest
         | 
| 2 2 | 
             
              class Runner
         | 
| 3 3 | 
             
                def self.in_browser?
         | 
| 4 4 | 
             
                  %x{
         | 
| @@ -41,7 +41,7 @@ module Spec | |
| 41 41 | 
             
                end
         | 
| 42 42 |  | 
| 43 43 | 
             
                def run
         | 
| 44 | 
            -
                  @groups =  | 
| 44 | 
            +
                  @groups = TestCase.test_cases.dup
         | 
| 45 45 | 
             
                  @formatter.start
         | 
| 46 46 | 
             
                  run_next_group
         | 
| 47 47 | 
             
                end
         | 
| @@ -0,0 +1,86 @@ | |
| 1 | 
            +
            module OpalTest
         | 
| 2 | 
            +
              class Spec < TestCase
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def self.stack
         | 
| 5 | 
            +
                  @stack ||= []
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def self.create(desc, block)
         | 
| 9 | 
            +
                  parent = Spec.stack.last
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  Class.new(parent || Spec) do
         | 
| 12 | 
            +
                    @desc   = desc
         | 
| 13 | 
            +
                    @parent = parent
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def self.to_s
         | 
| 18 | 
            +
                  "<OpalTest::Spec #{@desc.inspect}>"
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def self.description
         | 
| 22 | 
            +
                  @parent ? "#{@parent.description} #{@desc}" : @desc
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def self.it(desc, &block)
         | 
| 26 | 
            +
                  @specs ||= 0
         | 
| 27 | 
            +
                  define_method("test_#{@specs += 1}_#{desc}", &block)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def self.async(desc, &block)
         | 
| 31 | 
            +
                  self.it desc do
         | 
| 32 | 
            +
                    self.async!
         | 
| 33 | 
            +
                    instance_eval(&block)
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def self.let(name, &block)
         | 
| 38 | 
            +
                  define_method(name) do
         | 
| 39 | 
            +
                    @_memoized ||= {}
         | 
| 40 | 
            +
                    @_memoized.fetch(name) { |n| @_memoized[n] = instance_eval(&block) }
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def self.subject(&block)
         | 
| 45 | 
            +
                  let(:subject, &block)
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def self.it_behaves_like(*objs)
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                # type is ignored (is always :each)
         | 
| 52 | 
            +
                def self.before(type = nil, &block)
         | 
| 53 | 
            +
                  @setup_hooks << block
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                # type is ignored (is always :each)
         | 
| 57 | 
            +
                def self.after(type = nil, &block)
         | 
| 58 | 
            +
                  @teardown_hooks << block
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                def description
         | 
| 62 | 
            +
                  @description
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                def async!
         | 
| 66 | 
            +
                  @asynchronous = true
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                def run_async(&block)
         | 
| 70 | 
            +
                  begin
         | 
| 71 | 
            +
                    block.call
         | 
| 72 | 
            +
                  rescue => e
         | 
| 73 | 
            +
                    @exception = e
         | 
| 74 | 
            +
                  ensure
         | 
| 75 | 
            +
                    run_after_hooks
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
                  
         | 
| 78 | 
            +
                  finish_running
         | 
| 79 | 
            +
                end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                def set_timeout(duration, &block)
         | 
| 82 | 
            +
                  `setTimeout(#{block}, #{duration})`      
         | 
| 83 | 
            +
                  self
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
            end
         | 
| @@ -0,0 +1,120 @@ | |
| 1 | 
            +
            module OpalTest
         | 
| 2 | 
            +
              class TestCase
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                def self.test_cases
         | 
| 5 | 
            +
                  @test_cases ||= []
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def self.inherited(klass)
         | 
| 9 | 
            +
                  TestCase.test_cases << klass
         | 
| 10 | 
            +
                  klass.instance_eval { @setup_hooks = []; @teardown_hooks = [] }
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def self.description
         | 
| 14 | 
            +
                  to_s
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def self.run(runner)
         | 
| 18 | 
            +
                  @runner = runner
         | 
| 19 | 
            +
                  @runner.example_group_started self
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  @running_examples = self.instance_methods.grep(/^test_/)
         | 
| 22 | 
            +
                  run_next_example
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def self.run_next_example
         | 
| 26 | 
            +
                  if @running_examples.empty?
         | 
| 27 | 
            +
                    @runner.example_group_finished self
         | 
| 28 | 
            +
                  else
         | 
| 29 | 
            +
                    self.new(@running_examples.shift).run(@runner)
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def self.example_started(example)
         | 
| 34 | 
            +
                  @runner.example_started(example)
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def self.example_passed(example)
         | 
| 38 | 
            +
                  @runner.example_passed(example)
         | 
| 39 | 
            +
                  run_next_example
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def self.example_failed(example)
         | 
| 43 | 
            +
                  @runner.example_failed(example)
         | 
| 44 | 
            +
                  run_next_example
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def self.setup_hooks
         | 
| 48 | 
            +
                  @parent ? [].concat(@parent.setup_hooks).concat(@setup_hooks) : @setup_hooks
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                def self.teardown_hooks
         | 
| 52 | 
            +
                  @parent ? [].concat(@parent.teardown_hooks).concat(@teardown_hooks) : @teardown_hooks
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                def initialize(name)
         | 
| 56 | 
            +
                  @__name__ = name
         | 
| 57 | 
            +
                  @example_group = self.class
         | 
| 58 | 
            +
                  @description = name.sub(/^test_(\d)+_/, '')
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                def description
         | 
| 62 | 
            +
                  @__name__
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                attr_reader :example_group, :exception
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                def finish_running
         | 
| 68 | 
            +
                  if @exception
         | 
| 69 | 
            +
                    @example_group.example_failed self
         | 
| 70 | 
            +
                  else
         | 
| 71 | 
            +
                    @example_group.example_passed self
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                def run(runner)
         | 
| 76 | 
            +
                  @runner = runner
         | 
| 77 | 
            +
                  begin
         | 
| 78 | 
            +
                    @example_group.example_started self
         | 
| 79 | 
            +
                    run_before_hooks
         | 
| 80 | 
            +
                    setup
         | 
| 81 | 
            +
                    __send__ @__name__
         | 
| 82 | 
            +
                  rescue => e
         | 
| 83 | 
            +
                    @exception = e
         | 
| 84 | 
            +
                  ensure
         | 
| 85 | 
            +
                    unless @asynchronous
         | 
| 86 | 
            +
                      teardown
         | 
| 87 | 
            +
                      run_after_hooks
         | 
| 88 | 
            +
                    end
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  if @asynchronous
         | 
| 92 | 
            +
                    # must wait ...
         | 
| 93 | 
            +
                  else
         | 
| 94 | 
            +
                    finish_running
         | 
| 95 | 
            +
                  end
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                def run_after_hooks
         | 
| 99 | 
            +
                  begin
         | 
| 100 | 
            +
                    @example_group.teardown_hooks.each do |after|
         | 
| 101 | 
            +
                    instance_eval &after
         | 
| 102 | 
            +
                    end
         | 
| 103 | 
            +
                  rescue => e
         | 
| 104 | 
            +
                    @exception = e
         | 
| 105 | 
            +
                  end
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                def run_before_hooks
         | 
| 109 | 
            +
                  @example_group.setup_hooks.each do |before|
         | 
| 110 | 
            +
                    instance_eval &before
         | 
| 111 | 
            +
                  end
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                def setup
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                def teardown
         | 
| 118 | 
            +
                end
         | 
| 119 | 
            +
              end
         | 
| 120 | 
            +
            end
         | 
    
        data/lib/opal/spec/version.rb
    CHANGED
    
    
    
        data/opal-spec.gemspec
    CHANGED
    
    
    
        data/spec/specs.rb
    CHANGED
    
    | @@ -1,21 +1,14 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
             | 
| 3 | 
            -
             | 
| 4 | 
            -
            def assert(value, message='Not true')
         | 
| 5 | 
            -
              if value
         | 
| 6 | 
            -
                @passed += 1
         | 
| 7 | 
            -
              else
         | 
| 8 | 
            -
                @failures << message
         | 
| 9 | 
            -
              end
         | 
| 10 | 
            -
            end
         | 
| 1 | 
            +
            describe 'Normal group' do
         | 
| 2 | 
            +
              it 'exceptions can be thrown' do
         | 
| 3 | 
            +
                err = nil
         | 
| 11 4 |  | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 5 | 
            +
                begin
         | 
| 6 | 
            +
                  1.should == 2
         | 
| 7 | 
            +
                rescue => e
         | 
| 8 | 
            +
                  err = e
         | 
| 9 | 
            +
                end
         | 
| 15 10 |  | 
| 16 | 
            -
             | 
| 17 | 
            -
              it 'this should fail' do
         | 
| 18 | 
            -
                1.should == 2
         | 
| 11 | 
            +
                raise "exception not thrown" unless err
         | 
| 19 12 | 
             
              end
         | 
| 20 13 | 
             
            end
         | 
| 21 14 |  | 
| @@ -26,7 +19,7 @@ describe "New eql" do | |
| 26 19 | 
             
              end
         | 
| 27 20 |  | 
| 28 21 | 
             
              it "and this should fail" do
         | 
| 29 | 
            -
                1.should eq(:adam)
         | 
| 22 | 
            +
                lambda { 1.should eq(:adam) }.should raise_error(Exception)
         | 
| 30 23 | 
             
              end
         | 
| 31 24 | 
             
            end
         | 
| 32 25 |  | 
| @@ -41,10 +34,6 @@ describe 'Another group' do | |
| 41 34 | 
             
                1.should == 1
         | 
| 42 35 | 
             
              end
         | 
| 43 36 |  | 
| 44 | 
            -
              it 'this should fail' do
         | 
| 45 | 
            -
                raise "whatever error you like"
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
             | 
| 48 37 | 
             
              it 'this should pass' do
         | 
| 49 38 | 
             
                true.should be_true
         | 
| 50 39 | 
             
                false.should be_false
         | 
| @@ -62,12 +51,41 @@ describe 'Another group' do | |
| 62 51 | 
             
              async 'this should fail (in 0.1 second time)' do
         | 
| 63 52 | 
             
                set_timeout(100) do
         | 
| 64 53 | 
             
                  run_async {
         | 
| 65 | 
            -
                    1.should == 5
         | 
| 54 | 
            +
                    lambda { 1.should == 5 }.should raise_error(Exception)
         | 
| 66 55 | 
             
                  }
         | 
| 67 56 | 
             
                end
         | 
| 68 57 | 
             
              end
         | 
| 69 58 | 
             
            end
         | 
| 70 59 |  | 
| 71 | 
            -
             | 
| 60 | 
            +
            describe "let" do
         | 
| 61 | 
            +
              $opal_spec_let_count = 0
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              let(:count) { $opal_spec_let_count = $opal_spec_let_count + 1 }
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              it "caches the method for the example" do
         | 
| 66 | 
            +
                count.should eq(1)
         | 
| 67 | 
            +
                count.should eq(1)
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              it "does not cache values between different examples" do
         | 
| 71 | 
            +
                count.should eq(2)
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
            end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            describe "before" do
         | 
| 76 | 
            +
              before do
         | 
| 77 | 
            +
                @foo = 100
         | 
| 78 | 
            +
              end
         | 
| 72 79 |  | 
| 73 | 
            -
             | 
| 80 | 
            +
              before do
         | 
| 81 | 
            +
                @bar = 200
         | 
| 82 | 
            +
              end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
              it "should be run before each group" do
         | 
| 85 | 
            +
                @foo.should == 100
         | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
              it "should run multiple before blocks" do
         | 
| 89 | 
            +
                @bar.should == 200
         | 
| 90 | 
            +
              end
         | 
| 91 | 
            +
            end
         | 
    
        data/spec/tests.rb
    ADDED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: opal-spec
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.11
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,8 +9,24 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-02- | 
| 13 | 
            -
            dependencies: | 
| 12 | 
            +
            date: 2013-02-20 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: opal
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ~>
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: 0.3.38
         | 
| 22 | 
            +
              type: :runtime
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ~>
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: 0.3.38
         | 
| 14 30 | 
             
            description: Opal compatible spec library
         | 
| 15 31 | 
             
            email: adam.beynon@gmail.com
         | 
| 16 32 | 
             
            executables: []
         | 
| @@ -18,6 +34,7 @@ extensions: [] | |
| 18 34 | 
             
            extra_rdoc_files: []
         | 
| 19 35 | 
             
            files:
         | 
| 20 36 | 
             
            - .gitignore
         | 
| 37 | 
            +
            - CHANGELOG.md
         | 
| 21 38 | 
             
            - Gemfile
         | 
| 22 39 | 
             
            - README.md
         | 
| 23 40 | 
             
            - Rakefile
         | 
| @@ -25,15 +42,15 @@ files: | |
| 25 42 | 
             
            - lib/assets/javascripts/opal-spec.rb
         | 
| 26 43 | 
             
            - lib/assets/javascripts/opal/spec.rb
         | 
| 27 44 | 
             
            - lib/assets/javascripts/opal/spec/browser_formatter.rb
         | 
| 28 | 
            -
            - lib/assets/javascripts/opal/spec/example.rb
         | 
| 29 | 
            -
            - lib/assets/javascripts/opal/spec/example_group.rb
         | 
| 30 45 | 
             
            - lib/assets/javascripts/opal/spec/expectations.rb
         | 
| 31 46 | 
             
            - lib/assets/javascripts/opal/spec/kernel.rb
         | 
| 32 47 | 
             
            - lib/assets/javascripts/opal/spec/matchers.rb
         | 
| 33 48 | 
             
            - lib/assets/javascripts/opal/spec/phantom_formatter.rb
         | 
| 34 49 | 
             
            - lib/assets/javascripts/opal/spec/runner.rb
         | 
| 35 50 | 
             
            - lib/assets/javascripts/opal/spec/scratch_pad.rb
         | 
| 51 | 
            +
            - lib/assets/javascripts/opal/spec/spec.rb
         | 
| 36 52 | 
             
            - lib/assets/javascripts/opal/spec/sprockets_runner.rb.erb
         | 
| 53 | 
            +
            - lib/assets/javascripts/opal/spec/test_case.rb
         | 
| 37 54 | 
             
            - lib/opal-spec.rb
         | 
| 38 55 | 
             
            - lib/opal/spec.rb
         | 
| 39 56 | 
             
            - lib/opal/spec/rake_task.rb
         | 
| @@ -41,6 +58,7 @@ files: | |
| 41 58 | 
             
            - lib/opal/spec/version.rb
         | 
| 42 59 | 
             
            - opal-spec.gemspec
         | 
| 43 60 | 
             
            - spec/specs.rb
         | 
| 61 | 
            +
            - spec/tests.rb
         | 
| 44 62 | 
             
            - vendor/spec_runner.html.erb
         | 
| 45 63 | 
             
            - vendor/spec_runner.js
         | 
| 46 64 | 
             
            homepage: http://opalrb.org
         | 
| @@ -1,76 +0,0 @@ | |
| 1 | 
            -
            module Spec
         | 
| 2 | 
            -
              class Example
         | 
| 3 | 
            -
                attr_reader :description, :example_group, :exception
         | 
| 4 | 
            -
                attr_accessor :asynchronous
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                def initialize(group, desc, block)
         | 
| 7 | 
            -
                  @example_group = group
         | 
| 8 | 
            -
                  @description   = desc
         | 
| 9 | 
            -
                  @__block__     = block
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                def finish_running
         | 
| 13 | 
            -
                  if @exception
         | 
| 14 | 
            -
                    @example_group.example_failed self
         | 
| 15 | 
            -
                  else
         | 
| 16 | 
            -
                    @example_group.example_passed self
         | 
| 17 | 
            -
                  end
         | 
| 18 | 
            -
                end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                def run
         | 
| 21 | 
            -
                  begin
         | 
| 22 | 
            -
                    @example_group.example_started self
         | 
| 23 | 
            -
                    run_before_hooks
         | 
| 24 | 
            -
                    instance_eval(&@__block__)
         | 
| 25 | 
            -
                  rescue => e
         | 
| 26 | 
            -
                    @exception = e
         | 
| 27 | 
            -
                  ensure
         | 
| 28 | 
            -
                    run_after_hooks unless @asynchronous
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  if @asynchronous
         | 
| 32 | 
            -
                    # must wait ...
         | 
| 33 | 
            -
                  else
         | 
| 34 | 
            -
                    finish_running
         | 
| 35 | 
            -
                  end
         | 
| 36 | 
            -
                end
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                def run_after_hooks
         | 
| 39 | 
            -
                  begin
         | 
| 40 | 
            -
                    @example_group.after_hooks.each do |after|
         | 
| 41 | 
            -
                    instance_eval &after
         | 
| 42 | 
            -
                    end
         | 
| 43 | 
            -
                  rescue => e
         | 
| 44 | 
            -
                    @exception = e
         | 
| 45 | 
            -
                  end
         | 
| 46 | 
            -
                end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                def run_before_hooks
         | 
| 49 | 
            -
                  @example_group.before_hooks.each do |before|
         | 
| 50 | 
            -
                    instance_eval &before
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                def run_async(&block)
         | 
| 55 | 
            -
                  begin
         | 
| 56 | 
            -
                    block.call
         | 
| 57 | 
            -
                  rescue => e
         | 
| 58 | 
            -
                    @exception = e
         | 
| 59 | 
            -
                  ensure
         | 
| 60 | 
            -
                    run_after_hooks
         | 
| 61 | 
            -
                  end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                  finish_running
         | 
| 64 | 
            -
                end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                def set_timeout(duration, &block)
         | 
| 67 | 
            -
                  %x{
         | 
| 68 | 
            -
                    setTimeout(function() {
         | 
| 69 | 
            -
                      #{ block.call };
         | 
| 70 | 
            -
                    }, duration);
         | 
| 71 | 
            -
                  }
         | 
| 72 | 
            -
             | 
| 73 | 
            -
                  self
         | 
| 74 | 
            -
                end
         | 
| 75 | 
            -
              end
         | 
| 76 | 
            -
            end
         | 
| @@ -1,92 +0,0 @@ | |
| 1 | 
            -
            module Spec
         | 
| 2 | 
            -
              class ExampleGroup
         | 
| 3 | 
            -
                @example_groups = []
         | 
| 4 | 
            -
                def self.example_groups
         | 
| 5 | 
            -
                  @example_groups
         | 
| 6 | 
            -
                end
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                @stack = []
         | 
| 9 | 
            -
                def self.create desc, block
         | 
| 10 | 
            -
                  group = self.new desc, @stack.last
         | 
| 11 | 
            -
                  @example_groups << group
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                  @stack << group
         | 
| 14 | 
            -
                  group.instance_eval &block
         | 
| 15 | 
            -
                  @stack.pop
         | 
| 16 | 
            -
                end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                def initialize desc, parent
         | 
| 19 | 
            -
                  @desc     = desc.to_s
         | 
| 20 | 
            -
                  @parent   = parent
         | 
| 21 | 
            -
                  @examples = []
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                  @before_hooks = []
         | 
| 24 | 
            -
                  @after_hooks  = []
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                def it(desc, &block)
         | 
| 28 | 
            -
                  @examples << Example.new(self, desc, block)
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                def async(desc, &block)
         | 
| 32 | 
            -
                  example = Example.new(self, desc, block)
         | 
| 33 | 
            -
                  example.asynchronous = true
         | 
| 34 | 
            -
                  @examples << example
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                def it_behaves_like(*objs)
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                def before type = :each, &block
         | 
| 41 | 
            -
                  raise "unsupported before type: #{type}" unless type == :each
         | 
| 42 | 
            -
                  @before_hooks << block
         | 
| 43 | 
            -
                end
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                def after type = :each, &block
         | 
| 46 | 
            -
                  raise "unsupported after type: #{type}" unless type == :each
         | 
| 47 | 
            -
                  @after_hooks << block
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                def before_hooks
         | 
| 51 | 
            -
                  @parent ? [].concat(@parent.before_hooks).concat(@before_hooks) : @before_hooks
         | 
| 52 | 
            -
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                def after_hooks
         | 
| 55 | 
            -
                  @parent ? [].concat(@parent.after_hooks).concat(@after_hooks) : @after_hooks
         | 
| 56 | 
            -
                end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                def run(runner)
         | 
| 59 | 
            -
                  @runner = runner
         | 
| 60 | 
            -
                  @runner.example_group_started self
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                  @running_examples = @examples.dup
         | 
| 63 | 
            -
                  run_next_example
         | 
| 64 | 
            -
                end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                def run_next_example
         | 
| 67 | 
            -
                  if @running_examples.empty?
         | 
| 68 | 
            -
                    @runner.example_group_finished self
         | 
| 69 | 
            -
                  else
         | 
| 70 | 
            -
                    @running_examples.shift.run
         | 
| 71 | 
            -
                  end
         | 
| 72 | 
            -
                end
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                def example_started(example)
         | 
| 75 | 
            -
                  @runner.example_started(example)
         | 
| 76 | 
            -
                end
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                def example_passed(example)
         | 
| 79 | 
            -
                  @runner.example_passed(example)
         | 
| 80 | 
            -
                  run_next_example
         | 
| 81 | 
            -
                end
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                def example_failed(example)
         | 
| 84 | 
            -
                  @runner.example_failed(example)
         | 
| 85 | 
            -
                  run_next_example
         | 
| 86 | 
            -
                end
         | 
| 87 | 
            -
             | 
| 88 | 
            -
                def description
         | 
| 89 | 
            -
                  @parent ? "#{@parent.description} #{@desc}" : @desc
         | 
| 90 | 
            -
                end
         | 
| 91 | 
            -
              end
         | 
| 92 | 
            -
            end
         |