require 'rspec'
#require 'C:\amsrc\rmtry\lib\cart.rb'
require_relative './lib/cart'
#require_relative '././lib/cart' # C:/amsrc/rmtry/specZFut/lib/cart (LoadError)
# require_relative '../../lib/cart' # C:/amsrc/lib/cart (LoadError)
# #require_relative './lib/cart' # C:/amsrc/rmtry/specZFut/lib/cart (LoadError)
require './lib/store'
#require 'ruby-debug'
require './specLib/custom_stdout_matcher'

#LOAD BUGS
=begin

==========================================================
    75.[] ; X.ruby on rails - relative File Path in RSpec - Stack Overflow
http://stackoverflow.com/questions/9345412/relative-file-path-in-rspec
ruby on rails - relative File Path in RSpec - Stack Overflow

==========================================================
    76.[] ; X.ruby - How to load a spec_helper.rb automatically in RSpec 2 - Stack Overflow
http://stackoverflow.com/questions/5061179/how-to-load-a-spec-helper-rb-automatically-in-rspec-2
ruby - How to load a spec_helper.rb automatically in RSpec 2 - Stack Overflow

==========================================================
    77.[] ; X.Default spec_helper configuration generated by 'rspec --init' is non-intuitive by jasonkarns · Pull Request #796 · rspec/rspec-core
https://github.com/rspec/rspec-core/pull/796
Default spec_helper configuration generated by 'rspec --init' is non-intuitive by jasonkarns · Pull Request #796 · rspec/rspec-core

==========================================================
    78.[] ; X.rspec-core/lib/rspec/core/project_initializer.rb at master · rspec/rspec-core
https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/project_initializer.rb
rspec-core/lib/rspec/core/project_initializer.rb at master · rspec/rspec-core

==========================================================
    79.[] ; X.rspec-core/lib/rspec/core/project_initializer/spec_helper.rb at master · rspec/rspec-core
https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/project_initializer/spec_helper.rb
rspec-core/lib/rspec/core/project_initializer/spec_helper.rb at master · rspec/rspec-core

==========================================================
    80.[] ; X.rspec - Ruby Debug "no such file to load --spec_helper" - Stack Overflow
http://stackoverflow.com/questions/5045867/ruby-debug-no-such-file-to-load-spec-helper
rspec - Ruby Debug "no such file to load --spec_helper" - Stack Overflow

=end


describe 'Rspec with Let and Sysout' do
  it 'Is testable by capturing sysout.' do
    pending 'IDK how to use the let(:outs) statement.'
  #    let(:outs) { [] }  #double('output')}
  #    let(:term) {Terminal::TerminalPos.new(['g'])}
  #    let(:term) {Terminal.new(:outs)}
  end
end

describe 'Cart' do
  #before(:each) do
  #  @aStore1 = (Store::Store.new).add_product('a', 1)
  #  @aCart1 = Cart::Cart.new(@aStore1)
  #end
  def new_Cart_with_StoreHavingProduct(aProductId=nil, aPrice=1)
    store = Store::Store.new
    store.add_product(aProductId, aPrice) if !aProductId.nil?
    cart = Cart::Cart.new(store)
    return cart, store
  end

  #let(:aCart0) { Cart::Cart.new( Store::Store.new ) }
  #let(:aCart1) { Cart_with_StoreHavingProductA }

  it '#add  add a new item.' do
    aCart0, aStore0 = new_Cart_with_StoreHavingProduct(nil)
    expect(aStore0.report).to eq("[]")
    aCart1, aStore1 = new_Cart_with_StoreHavingProduct('a')
    expect(aStore1.report).to eq("[{:id=>\"a\", :price=>100, :numberForBatchDiscount=>0, :batchPrice=>0}]")
    print (aCart1.report)
    aCart1.add('a')
    #debugger
    print (aCart1.report)
    expect{aCart1.add('b')}.to raise_error "Error, Your product could not be found in the store. Please re-enter."
    # RuntimeError" #"
  end

  it '#add  add a new item.' do
    pending 'let is not working with fcn'
    expect{aCart1.add('a')}.to raise_error ArgumentError
  end
end