Skip to content

Commit

Permalink
#57 book_spec.rb passes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsomel21 committed Oct 27, 2023
1 parent de79b39 commit 14d1b2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ group :development, :test do
gem 'factory_bot_rails'

gem 'dotenv-rails'

# CLI Stuff
gem 'diffy'
gem 'tty-prompt'
end

group :development do
Expand All @@ -68,10 +72,6 @@ group :development do
gem 'rubocop-capybara'
gem 'rubocop-rails'
gem 'rubocop-rspec', :require => false

# CLI Stuff
gem 'diffy'
gem 'tty-prompt'
end

group :test do
Expand Down
25 changes: 13 additions & 12 deletions spec/models/book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
it 'raises an error if the CSV does not exist' do
# Create the `Chapter` row only! Not the CSV.
create(:chapter, :book => book, :number => 100)
expect { book.import_chapter(100) }.to raise_error(RuntimeError, 'CSV file lib/imports/1/100.csv not found')
expect { book.import_chapter(100) }.to raise_error(RuntimeError, %r{CSV file lib/imports/1/100\.csv not found})
end
end

Expand All @@ -26,9 +26,9 @@
CSV

csv_rows = CSV.parse(csv_content, :headers => true)
let(:chapter) { create(:chapter, :book => book) }

it 'does not raise an error' do
let(:chapter) { create(:chapter, :book => book) }
file_path = "lib/imports/#{book.sequence}/#{chapter.number}.csv"

allow(File).to receive(:exist?).with(file_path).and_return(true)
Expand All @@ -49,16 +49,18 @@
CSV
end

let(:chapter) { create(:chapter, :number => chapter_number, :book => book, :title => chapter_title) }
let(:chhand_type) { create(:chhand_type, :name => 'ਦੋਹਰਾ') }
let(:chhand) { create(:chhand, :chhand_type => chhand_type, :chapter => chapter) }
let(:pauri) { create(:pauri, :chapter => chapter, :chhand => chhand, :number => 1) }
let(:prompt) { instance_double(TTY::Prompt) }

before do
# Initialize mocks for TTY::Prompt
prompt = instance_double(TTY::Prompt)
allow(TTY::Prompt).to receive(:new).and_return(prompt)
allow(prompt).to receive(:say)

# Associations for the chapter - This one reflects out mock `csv_content`
let(:chapter) { create(:chapter, :number => chapter_number, :book => book, :title => chapter_title) }
let(:chhand) { create(:chhand, :chhand_type => '', :chapter => chapter) }
let(:pauri) { create(:pauri, :chapter => chapter, :chhand => chhand, :number => 1) }
create(:tuk, :pauri => pauri, :chapter => chapter, :original_content => 'ਤੀਨੋ ਕਾਲ ਅਲਿਪਤ ਰਹਿ, ਖੋਜੈਂ ਜਾਂਹਿ ਪ੍ਰਬੀਨ', :sequence => 1)
create(:tuk, :pauri => pauri, :chapter => chapter, :original_content => 'ਬੀਨਤਿ ਸਚਿਦਾਨੰਦ ਤ੍ਰੈ, ਜਾਨਹਿਂ ਮਰਮ ਰਤੀ ਨ', :sequence => 2)

Expand Down Expand Up @@ -103,18 +105,17 @@

it 'raises an error when `tuks` are nil' do
Tuk.destroy_all
expect { book.import_chapter(chapter_number) }.to raise_error(StandardError, /Tuk not found/)
expect { book.import_chapter(chapter_number) }.to raise_error(StandardError, /Tuk 1 not found/)
end

it 'raises an error when `tuk` content does not match' do
tuk = chapter.tuks.first
tuk.update(:content => 'Changed', :original_content => 'Totally Different')
Tuk.destroy_all
expect { book.import_chapter(chapter_number) }.to raise_error(StandardError, /Tuk not found/)
it 'raises an error when 2nd `tuk` is missing' do
chapter.tuks.second.destroy
expect { book.import_chapter(chapter_number) }.to raise_error(StandardError, /Tuk 2 not found/)
end
end

# TODO: Write tests for Translations, Footnotes, etc.
# TODO: and write tests for the TTY stuff
end
end
end
Expand Down

0 comments on commit 14d1b2c

Please sign in to comment.