spec/rpub/book_spec.rb in rpub-0.4.0 vs spec/rpub/book_spec.rb in rpub-0.5.0

- old
+ new

@@ -1,115 +1,115 @@ -require 'spec_helper' - describe Rpub::Book do - let(:subject) { described_class.new('some_file', 'title' => 'My "Awesome" Title!', 'version' => '1.0.3') } + let(:context) { Rpub::Context.new } + let(:subject) { described_class.new(context) } + before { allow(context).to receive(:chapter_files).and_return(['foo']) } + it { is_expected.to respond_to(:config) } - it 'should start with an empty configuration' do - described_class.new('some_file').config.should == {} - end - - it { should respond_to(:title) } - its(:title) { should == 'My "Awesome" Title!' } - its(:filename) { should == 'my-awesome-title-1.0.3.epub' } - describe 'chapters' do - before { subject.add_chapter 'foo' } + it 'has 1 chapter' do + expect(subject.chapters.size).to eq(1) + end - it { should have(1).chapters } + it { is_expected.to be_kind_of(Enumerable) } - it { should be_kind_of(Enumerable) } - - it 'should start with no chapters' do - described_class.new('foo').should have(0).chapters + it 'should start with context chapters' do + expect(subject.chapters.size).to eq(1) end it 'should allow chaining multiple calls' do subject << 'foo' << 'bar' - subject.should have(3).chapters + expect(subject.chapters.size).to eq(3) end it 'should yield chapters' do yielded = false subject.each { |c| yielded = true } - yielded.should be_true + expect(yielded).to be_truthy end end describe '#has_fonts?' do it 'should not have a font by default' do - described_class.new(nil, {}).should_not have_fonts + expect(context).to receive(:fonts).and_return([]) + is_expected.not_to have_fonts end - it 'should not have a font with an empty array' do - described_class.new(nil, nil, []).should_not have_fonts - end - it 'should have a font with a non-empty array' do - described_class.new(nil, nil, ['foo']).should have_fonts + expect(context).to receive(:fonts).and_return(['foo']) + is_expected.to have_fonts end end describe '#uid' do it 'should change when chapters change' do - Rpub::Book.new('bar').add_chapter('foo').should_not == subject.uid + expect(described_class.new(context).add_chapter('foo')).to_not eql(subject.uid) end it 'should change when config changes' do - Rpub::Book.new('bar', 'baz' => 'qux').should_not == subject.uid + expect(described_class.new(context)).to_not eql(subject.uid) end end describe '#outline' do + before { expect(context).to receive(:chapter_files).and_return([]) } + it 'should return empty array when there are no chapters' do - subject.outline.should be_empty + expect(subject.outline).to be_empty end it 'should return combination of all chapter outlines with filename' do subject << '# foo' << '# bar' - subject.outline.should have(2).elements + expect(subject.outline.size).to eq(2) end + + it 'should combine chapter outlines' do + subject << '# foo' << '# bar' + expect(subject.outline.first[0]).to eql('chapter-0-foo.html') + expect(subject.outline.first[1][0].text).to eql('foo') + end end describe '#has_cover?' do it 'should not have a cover without a config key' do - described_class.new(nil, {}).should_not have_cover + is_expected.not_to have_cover end it 'should not have a cover with a config key that is false' do - described_class.new(nil, { 'cover_image' => false }).should_not have_cover + expect(context).to receive(:config).and_return(OpenStruct.new({ 'cover_image' => false })) + is_expected.not_to have_cover end it 'should have a cover with a config key' do - described_class.new(nil, { 'cover_image' => true}).should have_cover + expect(context).to receive(:config).and_return(OpenStruct.new({ 'cover_image' => true })) + is_expected.to have_cover end end describe '#has_toc?' do it 'should not have a toc without a config key' do - described_class.new(nil, {}).should_not have_toc + expect(context).to receive(:config).and_return(OpenStruct.new) + is_expected.not_to have_toc end it 'should not have a toc with a config key that is false' do - described_class.new(nil, { 'toc' => false }).should_not have_toc + expect(context).to receive(:config).and_return(OpenStruct.new({ 'toc' => false })) + is_expected.not_to have_toc end it 'should have a toc with a config key' do - described_class.new(nil, { 'toc' => true }).should have_toc + expect(context).to receive(:config).and_return(OpenStruct.new({ 'toc' => true })) + is_expected.to have_toc end end describe '#images' do before { subject << '![foo](bar)' << '![baz](qux)' << '![bla](qux)' } - it { should have(2).images } - its(:images) { should include('bar') } - its(:images) { should include('qux') } - end - describe '#outline' do - before { subject << '# foo' << '## bar' } - its(:outline) { should have(2).elements } - it 'should combine chapter outlines' do - subject.outline.first[0].should == 'chapter-0-foo.html' - subject.outline.first[1][0].text.should == 'foo' + it 'has 2 images' do + expect(subject.images.size).to eq(2) + end + + it 'has includes each unique image' do + expect(subject.images).to include('bar', 'qux') end end end