Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
523c544
commit 27d0aaf
Showing
6 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
require_relative "./computer/boot" | ||
|
||
# http://ruby-for-beginners.rubymonstas.org/advanced/modules.html | ||
# Main computer module. This file just initializes the module naming convention we use in this project. | ||
module Computer; end | ||
|
||
require_relative "./computer/boot" | ||
require_relative "./computer/system/system" | ||
require_relative "./computer/app/app" | ||
|
||
# Computer::Boot.new.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# TODO: create your desktop icons. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ module System; end | |
end | ||
|
||
require_relative "./login.rb" | ||
require_relative "./desktop.rb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
describe Computer::System::Login do | ||
let(:pin) { "1234" } | ||
|
||
# The `#` symbol means we are describing an `instance` method in the class. | ||
describe "#prompt_user" do | ||
subject(:login) { described_class.new } | ||
|
||
before do | ||
allow_any_instance_of(described_class).to receive(:gets) { instance_double("gets.chomp", chomp: pin) } | ||
allow_any_instance_of(described_class).to receive(:user_input).and_return(false, true) | ||
end | ||
|
||
it "keeps prompting the user for a PIN until it gets a valid one" do | ||
expect { login.prompt_user }.to output(/The PIN is incorrect, try again/).to_stdout | ||
end | ||
|
||
it "prompts the user for a PIN" do | ||
expect { login.prompt_user }.to output(/In order to access this computer, please insert your PIN/).to_stdout | ||
end | ||
end | ||
|
||
# The `#` symbol means we are describing an `instance` method | ||
describe "#authenticate" do | ||
subject(:login) { described_class.new.authenticate(pin: pin_input) } | ||
|
||
let(:pin_input) { "" } | ||
|
||
before { stub_const("Computer::System::Login::PIN", pin) } | ||
|
||
it "has a PIN constant that holds the value to check against" do | ||
expect(described_class::PIN).to be_a(String) | ||
end | ||
|
||
context "when the pin is correct" do | ||
let(:pin_input) { pin } | ||
|
||
it "authenticates a user when a PIN is correctly filled" do | ||
expect(login).to eq true | ||
end | ||
end | ||
|
||
context "when the pin is incorrect" do | ||
let(:input_pin) { "wrong-pin" } | ||
|
||
it "doesn't authenticate a user when a PIN is incorrect" do | ||
expect(login).to eq false | ||
end | ||
end | ||
end | ||
end |