|
3 | 3 | describe PDFKit::Configuration do
|
4 | 4 | subject { PDFKit::Configuration.new }
|
5 | 5 | describe "#wkhtmltopdf" do
|
| 6 | + context "when explicitly configured" do |
| 7 | + it "uses configured value and don't detect" do |
| 8 | + expect(subject).not_to receive(:default_wkhtmltopdf) |
| 9 | + subject.wkhtmltopdf = "./Gemfile" # Need a file which exists |
| 10 | + expect(subject.wkhtmltopdf).to eq("./Gemfile") |
| 11 | + end |
| 12 | + |
| 13 | + it "falls back to detected binary if configured path doesn't exists" do |
| 14 | + expect(subject).to receive(:default_wkhtmltopdf).twice.and_return("/bin/fallback") |
| 15 | + expect(subject).to receive(:warn).with(/No executable found/) |
| 16 | + subject.wkhtmltopdf = "./missing-file" # Need a file which doesn't exist |
| 17 | + expect(subject.wkhtmltopdf).to eq("/bin/fallback") |
| 18 | + end |
| 19 | + end |
| 20 | + |
6 | 21 | context "when not explicitly configured" do
|
7 |
| - it "detects the existance of bundler" do |
8 |
| - # Test assumes bundler is installed in your test environment |
9 |
| - expect(subject).to receive(:`).with('bundle exec which wkhtmltopdf').and_return('c:\windows\path.exe') |
10 |
| - subject.wkhtmltopdf |
| 22 | + context "when running inside bundler" do |
| 23 | + # Simulate the presence of bundler even if it's not here |
| 24 | + before { stub_const("Bundler::GemfileError", Class) } |
| 25 | + |
| 26 | + it "detects the existance of bundler" do |
| 27 | + expect(subject).to receive(:`).with('bundle exec which wkhtmltopdf').and_return("c:\\windows\\path.exe\n") |
| 28 | + expect(subject.wkhtmltopdf).to eq('c:\windows\path.exe') |
| 29 | + end |
| 30 | + |
| 31 | + it "falls back if bundler path fails" do |
| 32 | + # This happens when there is a wrong (buggy) version of bundler for example |
| 33 | + expect(subject).to receive(:`).with('bundle exec which wkhtmltopdf').and_return("") |
| 34 | + expect(subject).to receive(:`).with('which wkhtmltopdf').and_return("c:\\windows\\path.exe\n") |
| 35 | + expect(subject.wkhtmltopdf).to eq('c:\windows\path.exe') |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + context "when running without bundler" do |
| 40 | + # Simulate the absence of bundler even if it's there |
| 41 | + before { hide_const("Bundler::GemfileError") } |
| 42 | + |
| 43 | + it "detects the existance of bundler" do |
| 44 | + expect(subject).not_to receive(:`).with('bundle exec which wkhtmltopdf') |
| 45 | + expect(subject).to receive(:`).with('which wkhtmltopdf').and_return('c:\windows\path.exe') |
| 46 | + expect(subject.wkhtmltopdf).to eq('c:\windows\path.exe') |
| 47 | + end |
11 | 48 | end
|
12 | 49 | end
|
13 | 50 | end
|
|
0 commit comments