Sha256: ec6dbcb926196272dc5b31c264934e1364566d9655e2e39b325b2ab8a94449c2

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require 'mastermind/cli'
require 'mastermind/play_game'
require 'mastermind/interact'
require 'spec_helper'
require 'stringio'

RSpec.describe Mastermind::CLI do
  it "should be able to quit" do
    stdin = StringIO.new("Q")
    cli = Mastermind::CLI.new(stdin, StringIO.new)
    expect(cli.quit?).to be_falsey

    cli.get_command
    expect(cli.quit?).to be_truthy

    stdin.string = "q"
    cli.get_command
    expect(cli.quit?).to be_truthy
  end

  it "should print intro title and content" do
    stdin = StringIO.new("\nq")
    stdout = StringIO.new()
    cli = Mastermind::CLI.new(stdin, stdout)
    cli.run
    expect(stdout.string).to include("0;32;49m")
    expect(stdout.string).to include("MA1N")
    expect(stdout.string).to include("_/")
  end

  it "should print instructions when prompted" do
    stdin = StringIO.new("i\nq")
    stdout = StringIO.new()
    cli = Mastermind::CLI.new(stdin, stdout)
    cli.run
    expect(stdout.string).to include("(i)")
  end

  it "should play the game when prompted" do
    stdin = StringIO.new("p\nq\nq\n")
    stdout = StringIO.new()
    cli = Mastermind::CLI.new(stdin, stdout)
    cli.run
    expect(Mastermind::PlayGame.new(stdin, stdout, Mastermind::Interact.new)).to respond_to(:run)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mastermind-nowsiany-1.0.2 spec/cli_spec.rb
mastermind-nowsiany-1.0.1 spec/cli_spec.rb
mastermind-nowsiany-1.0.0 spec/cli_spec.rb