Skip to content

Commit

Permalink
Update gems and fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
pacso committed Nov 1, 2021
1 parent d7330b2 commit e0aabae
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions aoc_rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "dotenv", "~> 2.7.6"
spec.add_dependency "httparty", "~> 0.18.1"
spec.add_dependency "thor", "~> 1.0.1"
spec.add_dependency "httparty", "~> 0.20.0"
spec.add_dependency "thor", "~> 1.1.0"
spec.add_dependency "rspec", "~> 3.0"
spec.add_dependency "nokogiri", "~> 1.10.10"
spec.add_dependency "nokogiri", "~> 1.12.5"

spec.add_development_dependency "webmock", "~> 3.10.0"
spec.add_development_dependency "webmock", "~> 3.14.0"
end
1 change: 1 addition & 0 deletions lib/aoc_rb/app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "httparty"
require 'dotenv/load'
require "fileutils"
require "thor"

require 'aoc_rb/aoc_api'
Expand Down
2 changes: 1 addition & 1 deletion lib/aoc_rb/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def new(name)
project_dir = File.join(Dir.getwd, name)
if File.exist?(project_dir)
puts "ERROR: #{project_dir} already exists!"
exit 0
exit -1
end

bin_dir = File.join(project_dir, "bin")
Expand Down
1 change: 1 addition & 0 deletions lib/aoc_rb/puzzle_input.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module AocRb
module PuzzleInput
extend self
Expand Down
25 changes: 11 additions & 14 deletions spec/lib/aoc_rb/cli_spec.rb → spec/lib/aoc_rb/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

RSpec.describe AocRb::Cli do
RSpec.describe AocRb::App do
let(:year) { Time.now.year }
let(:day) { Time.now.day }

Expand All @@ -23,20 +23,20 @@
end

it "sends a GET request to AOC for today's input" do
AocRb::Cli.start %w(fetch_input)
AocRb::App.start %w(fetch_input)
expect(WebMock).to have_requested(:get, "https://adventofcode.com/#{year}/day/#{day}/input")
end

it "can override the current date" do
AocRb::Cli.start %w(fetch_input -y 2018 -d 4)
AocRb::App.start %w(fetch_input -y 2018 -d 4)
expect(WebMock).to have_requested(:get, "https://adventofcode.com/2018/day/4/input")
end

it "saves the downloaded input into the correct challenge directory" do
challenge_dir = File.join(File.dirname(__FILE__), "../../..", "challenges", "2018", "04")
input_file = File.join(challenge_dir, "input.txt")

expect { AocRb::Cli.start %w(fetch_input -y 2018 -d 4) }.to change { File.exist?(input_file) }.from(false).to(true)
expect { AocRb::App.start %w(fetch_input -y 2018 -d 4) }.to change { File.exist?(input_file) }.from(false).to(true)
expect(File.read(input_file)).to eq puzzle_input
end
end
Expand Down Expand Up @@ -408,31 +408,28 @@
EOF
}

before do
stub_request(:get, "https://adventofcode.com/#{year}/day/#{day}").to_return({body: response_part_1})
stub_request(:get, "https://adventofcode.com/2018/day/4").to_return({body: response_part_1})
stub_request(:get, "https://adventofcode.com/2018/day/1").to_return({body: response_part_2})
end

it "sends a GET request to AOC for today's instructions" do
AocRb::Cli.start %w(fetch_instructions)
stub_request(:get, "https://adventofcode.com/#{year}/day/#{day}").to_return({body: response_part_1})
AocRb::App.start %w(fetch_instructions)
expect(WebMock).to have_requested(:get, "https://adventofcode.com/#{year}/day/#{day}")
end

it "converts the returned HTML into markdown and saves it to the correct challenge directory" do
stub_request(:get, "https://adventofcode.com/2018/day/4").to_return({body: response_part_1})
challenge_dir = File.join(File.dirname(__FILE__), "../../..", "challenges", "2018", "04")
part_1_file = File.join(challenge_dir, "part_1.md")
expect { AocRb::Cli.start %w(fetch_instructions 2018 4) }.to change { File.exist?(part_1_file) }.from(false).to(true)
expect(File.read(part_1_file)).to eq expected_markdown
expect { AocRb::App.start %w(fetch_instructions 2018 4) }.to change { File.exist?(part_1_file) }.from(false).to(true)
expect(File.read(part_1_file)).to eq markdown_part_1
end

it "correctly splits the instructions into two files when both parts are returned" do
stub_request(:get, "https://adventofcode.com/2018/day/1").to_return({body: response_part_2})
challenge_dir = File.join(File.dirname(__FILE__), "../../..", "challenges", "2018", "01")
part_1_file = File.join(challenge_dir, "part_1.md")
part_2_file = File.join(challenge_dir, "part_2.md")
expect(File.exist?(part_1_file)).to be false
expect(File.exist?(part_2_file)).to be false
AocRb::Cli.start %w(fetch_instructions 2018 1)
AocRb::App.start %w(fetch_instructions 2018 1)
expect(File.exist?(part_1_file)).to be true
expect(File.exist?(part_2_file)).to be true
expect(File.read(part_2_file)).to eq markdown_part_2
Expand Down

0 comments on commit e0aabae

Please sign in to comment.