Class: Arb::Files::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/arb/files/spec.rb

Class Method Summary collapse

Class Method Details

.create(year:, day:, notify_exists: true) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/arb/files/spec.rb', line 4

def self.create(year:, day:, notify_exists: true)
  year_directory = File.join("spec", year)
  Dir.mkdir(year_directory) unless Dir.exist?(year_directory)

  file_path = File.join(year_directory, "#{day}_spec.rb")

  if File.exist?(file_path)
    puts "Already exists: #{file_path}" if notify_exists
  else
    File.write(file_path, template(year:, day:))
  end

  file_path
end

.template(year:, day:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/arb/files/spec.rb', line 19

def self.template(year:, day:)
  <<~SPECS
    RSpec.describe Year#{year}::Day#{day} do
      let(:input) {
        StringIO.new(
          <<~IN
            something
          IN
        )
      }

      it "solves Part One" do
        expect(subject.part_1(input)).to eq(:todo)
      end

      xit "solves Part Two" do
        expect(subject.part_2(input)).to eq(:todo)
      end
    end
  SPECS
end