Sha256: 85e6900097f9af8a9ea4be1675292a29d3f33af2ff4b9faa726df0702de87fa4

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper.rb'

require 'reek/block_context'
require 'reek/method_context'

include Reek

describe BlockContext do

  it "should record single parameter" do
    element = StopContext.new
    element = BlockContext.new(element, s(s(:lasgn, :x), nil))
    element.variable_names.should == [Name.new(:x)]
  end

  it "should record single parameter within a method" do
    element = StopContext.new
    element = MethodContext.new(element, s(:defn, :help))
    element = BlockContext.new(element, s(s(:lasgn, :x), nil))
    element.variable_names.should == [Name.new(:x)]
  end

  it "records multiple parameters" do
    element = StopContext.new
    element = BlockContext.new(element, s(s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y))), nil))
    element.variable_names.should == [Name.new(:x), Name.new(:y)]
  end

  it "should not pass parameters upward" do
    mc = MethodContext.new(StopContext.new, s(:defn, :help))
    element = BlockContext.new(mc, s(s(:lasgn, :x)))
    mc.variable_names.should be_empty
  end

  it 'records local variables' do
    bctx = BlockContext.new(StopContext.new, nil)
    bctx.record_local_variable(:q2)
    bctx.variable_names.should include(Name.new(:q2))
  end

  it 'copes with a yield to an ivar' do
    scope = BlockContext.new(StopContext.new, [s(:iasgn, :@list), s(:self)])
    scope.record_instance_variable(:@list)
    scope.variable_names.should == [:@list]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kevinrutherford-reek-1.1.3.11 spec/reek/block_context_spec.rb
kevinrutherford-reek-1.1.3.12 spec/reek/block_context_spec.rb
kevinrutherford-reek-1.1.3.13 spec/reek/block_context_spec.rb
kevinrutherford-reek-1.1.3.14 spec/reek/block_context_spec.rb