Sha256: 06f572a76120a8e62a37b9c57485e659faa33937352f16e3bbd2ed6586904b9a

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 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(:iter, nil, 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(:iter, nil, 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(:iter, nil, 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, s(:args)))
    element = BlockContext.new(mc, s(:iter, nil, s(:lasgn, :x)))
    mc.variable_names.should be_empty
  end

  it 'records local variables' do
    bctx = BlockContext.new(StopContext.new, s(nil, 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(:iter, nil, s(:iasgn, :@list), s(:self)))
    scope.record_instance_variable(:@list)
    scope.variable_names.should == [:@list]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-1.2.5 spec/reek/block_context_spec.rb
reek-1.2.4 spec/reek/block_context_spec.rb
reek-1.2.3 spec/reek/block_context_spec.rb