Sha256: 7df71154b9f3a76eb4fbafe8186b79e0f1c8aefb466ec7e15d1b5f694a763f21

Contents?: true

Size: 759 Bytes

Versions: 49

Compression:

Stored size: 759 Bytes

Contents

require 'spec_helper'

class OpalReturnSpec
  def returning_expression
    (false || return)
  end

  def returning_block
    @values = []

    [1, 2, 3, 4, 5].each do |n|
      return if n == 3
      @values << n
    end
  end

  attr_reader :values

  def returning_block_value
    [1, 2, 3, 4, 5].each { return :foo }
  end
end

describe "The return statement" do
  it "can be used as an expression" do
    OpalReturnSpec.new.returning_expression.should be_nil
  end

  it "can return from a method when inside a block" do
    spec = OpalReturnSpec.new
    spec.returning_block
    spec.values.size.should == 2
  end

  it "returns the return value from a method returning by block" do
    OpalReturnSpec.new.returning_block_value.should == :foo
  end
end

Version data entries

49 entries across 49 versions & 3 rubygems

Version Path
opal-0.10.6 spec/opal/core/runtime/return_spec.rb
opal-0.10.6.beta spec/opal/core/runtime/return_spec.rb
opal-0.10.5 spec/opal/core/runtime/return_spec.rb
opal-0.10.4 spec/opal/core/runtime/return_spec.rb
opal-0.11.0.rc1 spec/opal/core/runtime/return_spec.rb
opal-0.10.3 spec/opal/core/runtime/return_spec.rb
opal-0.10.2 spec/opal/core/runtime/return_spec.rb
opal-0.10.1 spec/opal/core/runtime/return_spec.rb
opal-0.10.0 spec/opal/core/runtime/return_spec.rb
opal-0.10.0.rc2 spec/opal/core/runtime/return_spec.rb
opal-0.9.4 spec/opal/core/runtime/return_spec.rb
opal-0.9.3 spec/opal/core/runtime/return_spec.rb
opal-0.10.0.rc1 spec/opal/core/runtime/return_spec.rb
opal-0.10.0.beta5 spec/opal/core/runtime/return_spec.rb
opal-0.10.0.beta4 spec/opal/core/runtime/return_spec.rb
opal-0.10.0.beta3 spec/opal/core/runtime/return_spec.rb
opal-0.10.0.beta2 spec/opal/core/runtime/return_spec.rb
opal-0.10.0.beta1 spec/opal/core/runtime/return_spec.rb
opal-0.9.2 spec/opal/core/runtime/return_spec.rb
opal-0.9.0 spec/opal/core/runtime/return_spec.rb