Sha256: 9853729c8e6512d076665bc246508de4d0d809395b2d078df1231135069cdaab

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8

require 'spec_helper'
require 'astrolabe/sexp'

describe RuboCop::Cop::VariableForce::Variable do
  include Astrolabe::Sexp

  describe '.new' do
    context 'when non variable declaration node is passed' do
      it 'raises error' do
        name = :foo
        declaration_node = s(:def)
        scope = RuboCop::Cop::VariableForce::Scope.new(s(:class))
        expect { described_class.new(name, declaration_node, scope) }
          .to raise_error(ArgumentError)
      end
    end
  end

  describe '#referenced?' do
    let(:name) { :foo }
    let(:declaration_node) { s(:arg, name) }
    let(:scope) { double('scope').as_null_object }
    let(:variable) { described_class.new(name, declaration_node, scope) }

    subject { variable.referenced? }

    context 'when the variable is not assigned' do
      it { should be_falsey }

      context 'and the variable is referenced' do
        before do
          variable.reference!(s(:lvar, name))
        end

        it { should be_truthy }
      end
    end

    context 'when the variable has an assignment' do
      before do
        variable.assign(s(:lvasgn, name))
      end

      context 'and the variable is not yet referenced' do
        it { should be_falsey }
      end

      context 'and the variable is referenced' do
        before do
          variable.reference!(s(:lvar, name))
        end

        it { should be_truthy }
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/variable_force/variable_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/cop/variable_force/variable_spec.rb
rubocop-0.29.1 spec/rubocop/cop/variable_force/variable_spec.rb
rubocop-0.29.0 spec/rubocop/cop/variable_force/variable_spec.rb
rubocop-0.28.0 spec/rubocop/cop/variable_force/variable_spec.rb
rubocop-0.27.1 spec/rubocop/cop/variable_force/variable_spec.rb
rubocop-0.27.0 spec/rubocop/cop/variable_force/variable_spec.rb
rubocop-0.26.1 spec/rubocop/cop/variable_force/variable_spec.rb
rubocop-0.26.0 spec/rubocop/cop/variable_force/variable_spec.rb