describe OrderStringAnalyzer do describe '#read_and_execute!' do context 'order string pattern 1' do let(:order_string) do <<~ORDER_STRING.lines.map(&:strip).join("\n") make 10 nana getnum 1 getname 1 ORDER_STRING end it 'reads and executes the commands' do analyzer = OrderStringAnalyzer.new(order_string) analyzer.read_and_execute! expect(analyzer.employee_recorder.getnum(1)).to eq(10) end context 'when the command was done successfully' do it 'can read data from the execution histories' do analyzer = OrderStringAnalyzer.new(order_string) analyzer.read_and_execute! result = [10, 'nana'] expect(analyzer.execution_histories).to eq(result) end end end context 'order string pattern 2' do let(:order_string) do <<~ORDER_STRING.lines.map(&:strip).join("\n") make 2742 mako getnum 1 make 2782 taisei getname 2 make 31 megumi getname 1 getname 3 ORDER_STRING end it 'reads and executes the commands' do analyzer = OrderStringAnalyzer.new(order_string) analyzer.read_and_execute! expect(analyzer.employee_recorder.getnum(1)).to eq(2742) end context 'when the command was done successfully' do it 'can read data from the execution histories' do analyzer = OrderStringAnalyzer.new(order_string) analyzer.read_and_execute! result = [2742, 'taisei', 'mako', 'megumi'] expect(analyzer.execution_histories).to eq(result) end end end end end