-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow day argument to be "0" padded (#34)
* normalize day string input * add tests and update changelog * fix specs * Update spec formatting * Add newline * Update changelog with tag links --------- Co-authored-by: Christopher Moore <[email protected]> Co-authored-by: Jon Pascoe <[email protected]>
- Loading branch information
1 parent
fb6768b
commit b89d6a3
Showing
5 changed files
with
78 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
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,3 +1,3 @@ | ||
module AocRb | ||
VERSION = "0.2.9" | ||
VERSION = "0.2.10" | ||
end |
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,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe AocRb::AocApi do | ||
let(:session_token) { "test_session_token" } | ||
let(:year) { 2024 } | ||
let(:level) { 1 } | ||
let(:answer) { "42" } | ||
let(:api) { described_class.new(session_token) } | ||
|
||
shared_examples "consistent day path" do |day_input, expected_day| | ||
let(:expected_headers) { { 'Cookie' => "session=#{session_token}" } } | ||
|
||
describe "#puzzle_instructions" do | ||
let(:expected_path) { "/2024/day/#{expected_day}" } | ||
|
||
before do | ||
allow(api.class).to receive(:get).and_return(double('Response', body: '')) | ||
end | ||
|
||
it "sends the request to the correct uri" do | ||
api.puzzle_instructions(year, day_input) | ||
expect(api.class).to have_received(:get).with(expected_path, hash_including(headers: expected_headers)) | ||
end | ||
end | ||
|
||
describe "#puzzle_input" do | ||
let(:expected_path) { "/2024/day/#{expected_day}/input" } | ||
|
||
before do | ||
allow(api.class).to receive(:get).and_return(double('Response', body: '')) | ||
end | ||
|
||
it "sends the request to the correct uri" do | ||
api.puzzle_input(year, day_input) | ||
expect(api.class).to have_received(:get).with(expected_path, hash_including(headers: expected_headers)) | ||
end | ||
end | ||
|
||
describe "#submit_answer" do | ||
let(:expected_path) { "/2024/day/#{expected_day}/answer" } | ||
let(:expected_body) { { level: level.to_s, answer: answer.to_s } } | ||
|
||
before do | ||
allow(api.class).to receive(:post).and_return(double('Response', body: '')) | ||
end | ||
|
||
it "sends the request to the correct uri" do | ||
api.submit_answer(year, day_input, level, answer) | ||
expect(api.class).to have_received(:post).with(expected_path, hash_including(headers: expected_headers, body: expected_body)) | ||
end | ||
end | ||
end | ||
|
||
context "when day is an integer" do | ||
include_examples "consistent day path", 1, 1 | ||
include_examples "consistent day path", 17, 17 | ||
end | ||
|
||
context "when day is a two-character string" do | ||
include_examples "consistent day path", "01", 1 | ||
include_examples "consistent day path", "22", 22 | ||
end | ||
|
||
context "when day is a single character string" do | ||
include_examples "consistent day path", "8", 8 | ||
end | ||
end |
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