Sha256: 8f3e1224b85aafb12f8291de75f450afb86dddedc10d95fa3f57703dc07b63d6
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
# encoding: utf-8 require 'spec_helper' describe Rubocop::Cop::VariableForce::Variable do include AST::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_false } context 'and the variable is referenced' do before do variable.reference!(s(:lvar, name)) end it { should be_true } 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_false } end context 'and the variable is referenced' do before do variable.reference!(s(:lvar, name)) end it { should be_true } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.22.0 | spec/rubocop/cop/variable_force/variable_spec.rb |
rubocop-0.21.0 | spec/rubocop/cop/variable_force/variable_spec.rb |