require_relative '../../test_helper'
require_relative '../../integration/smart_answer_flows/flow_test_helper'

class FlowTestHelperTest < ActiveSupport::TestCase

  class FlowTestHelperIncluder
    include FlowTestHelper
    attr_accessor :responses

    def initialize(flow, responses)
      @flow = flow
      @responses = responses
    end
  end


  test "caches current_state" do
    flow = Object.new
    flow.expects(:process).once.returns(:state)
    includer = FlowTestHelperIncluder.new(flow, [:yes, :no])
    includer.current_state
    includer.current_state
  end

  test "busts current_state cache when responses change" do
    flow = Object.new
    flow.expects(:process).twice.returns(:state)
    responses = [:yes, :no]
    includer = FlowTestHelperIncluder.new(flow, responses)
    includer.current_state
    responses << :maybe
    includer.current_state
  end
end

require_relative '../../test_helper'
require_relative '../../integration/smart_answer_flows/flow_test_helper'

class FlowTestHelperTest < ActiveSupport::TestCase

  class FlowTestHelperIncluder
    include FlowTestHelper
    attr_accessor :responses

    def initialize(flow, responses)
      @flow = flow
      @responses = responses
    end
  end


  test "caches current_state" do
    flow = mock('flow')
    flow.expects(:process).once.returns(:state)
    includer = FlowTestHelperIncluder.new(flow, [:yes, :no])
    includer.current_state
    includer.current_state
  end

  test "busts current_state cache when responses change" do
    flow = mock('flow')
    flow.expects(:process).twice.returns(:state)
    responses = [:yes, :no]
    includer = FlowTestHelperIncluder.new(flow, responses)
    includer.current_state
    responses << :maybe
    includer.current_state
  end
end

Use mock object instead of Object instance w/ stubbed method
Use mock object instead of Object instance w/ stubbed method

There doesn't seem to be any good reason to use `Object.new` here and using
a bona fide mock object has the benefit of not having to stub a non-existent
method (i.e. `Object#process).
