Project

General

Profile

Bug #17093

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

```ruby 
 require 'rubygems' 

 class A 
   def initialize(type:) 
     @type = type 
   end 

   def b 
     p type 
     p type.nil? 
     type = 'default' if type.nil? 
     type 
   end 

   private 

   attr_accessor :type 
 end 

 RSpec.describe A do 
   let(:type) { 'whoaaa' } 

   it 'return default' do 
     expect(A.new(type: type).b).to eq('default') 
   end 

   it 'instance variable is "whoaaa"' do 
     expect(A.new(type: type).instance_variable_get(:@type)).to eq(type) 
   end 
 end 
 ``` 

 all tests green 

 ``` 
 output 
 A 
 "whoaaa" 
 false 
   return default 
   instance variable is "whoaaa" 
 ```

Back