diff options
Diffstat (limited to 'spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb')
-rw-r--r-- | spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb b/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb index d40be0e841c..43f0198704f 100644 --- a/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb +++ b/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb @@ -1,21 +1,41 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::ExposeAttribute do - it 'defines a getter method that returns an attribute value' do - klass = Class.new do + let(:klass) do + Class.new do include Gitlab::GithubImport::Representation::ExposeAttribute expose_attribute :number attr_reader :attributes - def initialize - @attributes = { number: 42 } + def initialize(attributes) + @attributes = attributes + end + end + end + + it 'defines a getter method that returns an attribute value' do + expect(klass.new({ number: 42 }).number).to eq(42) + end + + describe '#[]' do + it 'returns exposed attributes value using array notation' do + expect(klass.new({ number: 42 })[:number]).to eq(42) + end + + context 'when attribute does not exist' do + it 'returns nil' do + expect(klass.new({})[:number]).to eq(nil) end end - expect(klass.new.number).to eq(42) + context 'when attribute is not exposed' do + it 'returns nil' do + expect(klass.new({ not_exposed_attribute: 42 })[:not_exposed_attribute]).to eq(nil) + end + end end end |