I'm trying to test a "console" method that switches states. Each state has 
user input.  
I have test example on github https://github.com/dmitriy-sokolyanskiy/ref  
<https://github.com/dmitriy-sokolyanskiy/ref>
*Desired behavior:* in test I expect the "console" method to be launched  
with initial `@state = :greeting` and switching to `@state = :base_option`, 
which asks for user input, for example, `"create"`, which switches to 
`state = :main_menu`, which requires user input, for example, an `“exit”` 
that leads to an exit.  

    
    def console
     loop do
      break unless STATES.include?(@state)

      public_send(@state)
     end
    end

    def greeting
      message(:greeting)
      @state = :base_option
    end


    
*Problems:*

 1. it does not execute console input since `@states` does not change 
correctly. 
 2. `expect(current_subject).to receive(:create)`  - is not met.    

  

let(:current_subject) { described_class.new }
let(:input_sequence) { %w[create exit] }

describe '#console' do
  context 'when correct method calling' do
    after do
      # @state=:greeting
      current_subject.console
      # @state=nil
    end

    it 'create account if input is create' do
      allow(current_subject).to receive_message_chain(:gets, :chomp) { 
input_sequence }

      expect(current_subject).to receive(:create)
    end
  end
end


         
I'm stuck. Goodle doesn't know about it too (

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/6bbfcc23-eff0-4d2f-ad1d-2de8536598bc%40googlegroups.com.

Reply via email to