Skip to content

Commit 862f08e

Browse files
committed
Merge pull request #23 from jonmagic/update-specs-to-use-expect
Specify rspec version and update specs to expect syntax
2 parents 320cd6e + d58fd30 commit 862f08e

File tree

6 files changed

+47
-42
lines changed

6 files changed

+47
-42
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
source "https://rubygems.org"
22
gemspec
33
gem "rake"
4-
gem "rspec"
4+
gem "rspec", "~> 3.2.0"

spec/lib/grim/image_magick_processor_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
end
1717

1818
it "should return page count" do
19-
@processor.count(fixture_path("smoker.pdf")).should == 25
19+
expect(@processor.count(fixture_path("smoker.pdf"))).to eq(25)
2020
end
2121
end
2222

@@ -30,13 +30,13 @@
3030

3131
it "should create the file" do
3232
@processor.save(@pdf, 0, @path, {})
33-
File.exist?(@path).should be_true
33+
expect(File.exist?(@path)).to be(true)
3434
end
3535

3636
it "should use default width of 1024" do
3737
@processor.save(@pdf, 0, @path, {})
3838
width, height = dimensions_for_path(@path)
39-
width.should == 1024
39+
expect(width).to eq(1024)
4040
end
4141
end
4242

@@ -50,7 +50,7 @@
5050

5151
it "should set width" do
5252
width, height = dimensions_for_path(@path)
53-
width.should == 20
53+
expect(width).to eq(20)
5454
end
5555
end
5656

@@ -67,7 +67,7 @@
6767
Grim::ImageMagickProcessor.new.save(@pdf, 0, @path, {:quality => 90})
6868
higher_size = File.size(@path)
6969

70-
(lower_size < higher_size).should be_true
70+
expect(lower_size < higher_size).to be(true)
7171
end
7272
end
7373

@@ -81,7 +81,7 @@
8181
lower_time = Benchmark.realtime { Grim::ImageMagickProcessor.new.save(@pdf, 0, @path, {:density => 72}) }
8282
higher_time = Benchmark.realtime { Grim::ImageMagickProcessor.new.save(@pdf, 0, @path, {:density => 300}) }
8383

84-
(lower_time < higher_time).should be_true
84+
expect(lower_time < higher_time).to be(true)
8585
end
8686
end
8787

@@ -99,7 +99,7 @@
9999
file1_size = File.stat(@path1).size
100100
file2_size = File.stat(@path2).size
101101

102-
file1_size.should_not == file2_size
102+
expect(file1_size).to_not eq(file2_size)
103103
end
104104
end
105-
end
105+
end

spec/lib/grim/multi_processor_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,29 @@
1414

1515
describe "#count" do
1616
it "should try processors until it succeeds" do
17-
@failure.stub(:count){""}
18-
@success.should_receive(:count).and_return(30)
19-
@extra.should_not_receive(:count)
17+
allow(@failure).to receive(:count).and_return("")
18+
expect(@success).to receive(:count).and_return(30)
19+
expect(@extra).to_not receive(:count)
2020

2121
@processor.count(@path)
2222
end
2323
end
2424

2525
describe "#save" do
2626
it "should try processors until it succeeds" do
27-
@failure.stub(:save){false}
28-
@success.should_receive(:save).and_return(true)
29-
@extra.should_not_receive(:save)
27+
allow(@failure).to receive(:save).and_return(false)
28+
expect(@success).to receive(:save).and_return(true)
29+
expect(@extra).to_not receive(:save)
3030

3131
@processor.save(@pdf, 0, @path, {})
3232
end
3333

3434
it "should raise error if all processors fail" do
35-
@failure.should_receive(:save).and_return(false)
36-
@success.should_receive(:save).and_return(false)
37-
@extra.should_receive(:save).and_return(false)
35+
expect(@failure).to receive(:save).and_return(false)
36+
expect(@success).to receive(:save).and_return(false)
37+
expect(@extra).to receive(:save).and_return(false)
3838

39-
lambda { @processor.save(@pdf, 0, @path, {}) }.should raise_error(Grim::UnprocessablePage)
39+
expect { @processor.save(@pdf, 0, @path, {}) }.to raise_error(Grim::UnprocessablePage)
4040
end
4141
end
42-
end
42+
end

spec/lib/grim/page_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
end
99

1010
it "should have number" do
11-
Grim::Page.new(Grim::Pdf.new(fixture_path("smoker.pdf")), 1).number.should == 2
11+
expect(Grim::Page.new(Grim::Pdf.new(fixture_path("smoker.pdf")), 1).number).to eq(2)
1212
end
1313

1414
describe "#save" do
@@ -18,7 +18,7 @@
1818
end
1919

2020
it "should call Grim.processor.save with pdf, index, path, and options" do
21-
Grim.processor.should_receive(:save).with(@pdf, 0, @path, {})
21+
expect(Grim.processor).to receive(:save).with(@pdf, 0, @path, {})
2222
@pdf[0].save(@path)
2323
end
2424
end
@@ -30,8 +30,8 @@
3030
end
3131

3232
it "raises an exception" do
33-
lambda { @pdf[0].save(nil) }.should raise_error(Grim::PathMissing)
34-
lambda { @pdf[0].save(' ') }.should raise_error(Grim::PathMissing)
33+
expect { @pdf[0].save(nil) }.to raise_error(Grim::PathMissing)
34+
expect { @pdf[0].save(' ') }.to raise_error(Grim::PathMissing)
3535
end
3636
end
3737

@@ -47,13 +47,15 @@
4747
describe "#text" do
4848
it "should return the text from the selected page" do
4949
pdf = Grim::Pdf.new(fixture_path("smoker.pdf"))
50-
pdf[1].text.should == "Step 1: get someone to print this curve for you to scale, 72” wide\nStep 2: Get a couple 55 gallon drums\n\n\f"
50+
expect(pdf[1].text).to \
51+
eq("Step 1: get someone to print this curve for you to scale, 72” wide\nStep 2: Get a couple 55 gallon drums\n\n\f")
5152
end
5253

5354
it "works with full path to pdftotext" do
5455
pdftotext_path = `which pdftotext`.chomp
5556
pdf = Grim::Pdf.new(fixture_path("smoker.pdf"), pdftotext_path: pdftotext_path)
56-
pdf[1].text.should == "Step 1: get someone to print this curve for you to scale, 72” wide\nStep 2: Get a couple 55 gallon drums\n\n\f"
57+
expect(pdf[1].text).to \
58+
eq("Step 1: get someone to print this curve for you to scale, 72” wide\nStep 2: Get a couple 55 gallon drums\n\n\f")
5759
end
5860
end
5961
end

spec/lib/grim/pdf_spec.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
44
describe Grim::Pdf do
55

66
it "should have a path" do
7-
Grim::Pdf.new(fixture_path("smoker.pdf")).path.should == fixture_path("smoker.pdf")
7+
pdf = Grim::Pdf.new(fixture_path("smoker.pdf"))
8+
expect(pdf.path).to eq(fixture_path("smoker.pdf"))
89
end
910

1011
describe "#initialize" do
1112
it "should raise an error if pdf does not exist" do
12-
lambda { Grim::Pdf.new(fixture_path("booboo.pdf")) }.should raise_error(Grim::PdfNotFound)
13+
expect {
14+
Grim::Pdf.new(fixture_path("booboo.pdf"))
15+
}.to raise_error(Grim::PdfNotFound)
1316
end
1417

1518
it "should set path on pdf" do
1619
pdf = Grim::Pdf.new(fixture_path("smoker.pdf"))
17-
pdf.path.should == fixture_path("smoker.pdf")
20+
expect(pdf.path).to eq(fixture_path("smoker.pdf"))
1821
end
1922
end
2023

2124
describe "#count" do
2225
it "should call Grim.processor.count with pdf path" do
23-
Grim.processor.should_receive(:count).with(fixture_path("smoker.pdf"))
26+
expect(Grim.processor).to receive(:count).with(fixture_path("smoker.pdf"))
2427
pdf = Grim::Pdf.new(fixture_path("smoker.pdf"))
2528
pdf.count
2629
end
@@ -32,19 +35,19 @@
3235
end
3336

3437
it "should raise Grim::PageDoesNotExist if page doesn't exist" do
35-
lambda { @pdf[25] }.should raise_error(Grim::PageNotFound)
38+
expect { @pdf[25] }.to raise_error(Grim::PageNotFound)
3639
end
3740

3841
it "should return an instance of Grim::Page if page exists" do
39-
@pdf[24].class.should == Grim::Page
42+
expect(@pdf[24].class).to eq(Grim::Page)
4043
end
4144
end
4245

4346
describe "#each" do
4447
it "should be iterable" do
4548
pdf = Grim::Pdf.new(fixture_path("smoker.pdf"))
46-
pdf.map {|p| p.number }.should == (1..25).to_a
49+
expect(pdf.map {|p| p.number }).to eq((1..25).to_a)
4750
end
4851
end
4952

50-
end
53+
end

spec/lib/grim_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33

44
describe Grim do
55
it "should have a default processor" do
6-
Grim.processor.class.should == Grim::ImageMagickProcessor
6+
expect(Grim.processor.class).to eq(Grim::ImageMagickProcessor)
77
end
88

99
it "should have a VERSION constant" do
10-
Grim.const_defined?('VERSION').should be_true
10+
expect(Grim.const_defined?('VERSION')).to be(true)
1111
end
1212

1313
it "should have WIDTH constant set to 1024" do
14-
Grim::WIDTH.should == 1024
14+
expect(Grim::WIDTH).to eq(1024)
1515
end
1616

1717
it "should have QUALITY constant set to 90" do
18-
Grim::QUALITY.should == 90
18+
expect(Grim::QUALITY).to eq(90)
1919
end
2020

2121
it "should have DENSITY constant set to 300" do
22-
Grim::DENSITY.should == 300
22+
expect(Grim::DENSITY).to eq(300)
2323
end
2424

2525
it "should have COLORSPACE constant set to 'RGB'" do
26-
Grim::COLORSPACE.should == 'RGB'
26+
expect(Grim::COLORSPACE).to eq('RGB')
2727
end
2828

2929
describe "#reap" do
3030
it "should return an instance of Grim::Pdf" do
31-
Grim.reap(fixture_path("smoker.pdf")).class.should == Grim::Pdf
31+
expect(Grim.reap(fixture_path("smoker.pdf")).class).to eq(Grim::Pdf)
3232
end
3333
end
34-
end
34+
end

0 commit comments

Comments
 (0)