|
1 | 1 | require "rack/console" |
2 | 2 | require "irb" |
| 3 | +require "pry" |
3 | 4 |
|
4 | 5 | describe Rack::Console do |
5 | 6 | before do |
6 | 7 | @old_pwd = Dir.pwd |
7 | 8 | Dir.chdir File.expand_path("../../support", __FILE__) |
8 | 9 |
|
9 | | - expect(IRB).to receive(:start) |
| 10 | + allow(IRB).to receive(:start) |
| 11 | + allow(Pry).to receive(:start) |
10 | 12 | end |
11 | 13 |
|
12 | | - it "defaults to a config.ru file in the current working directory" do |
13 | | - expect(Rack::Builder).to receive(:parse_file) |
14 | | - .with("config.ru") |
15 | | - .and_call_original |
| 14 | + context "when using IRB" do |
| 15 | + before do |
| 16 | + expect(IRB).to receive(:start) |
| 17 | + expect(Pry).not_to receive(:start) |
| 18 | + end |
16 | 19 |
|
17 | | - Rack::Console.new.start |
18 | | - end |
| 20 | + it "defaults to a config.ru file in the current working directory" do |
| 21 | + expect(Rack::Builder).to receive(:parse_file) |
| 22 | + .with("config.ru") |
| 23 | + .and_call_original |
19 | 24 |
|
20 | | - it "accepts the --config option to override the location of config.ru" do |
21 | | - Dir.chdir @old_pwd |
22 | | - expect(Rack::Builder).to receive(:parse_file) |
23 | | - .with("spec/support/config.ru") |
24 | | - .and_call_original |
| 25 | + Rack::Console.new.start |
| 26 | + end |
25 | 27 |
|
26 | | - Rack::Console.new(config: "spec/support/config.ru").start |
27 | | - end |
| 28 | + it "accepts the --config option to override the location of config.ru" do |
| 29 | + Dir.chdir @old_pwd |
| 30 | + expect(Rack::Builder).to receive(:parse_file) |
| 31 | + .with("spec/support/config.ru") |
| 32 | + .and_call_original |
28 | 33 |
|
29 | | - it "accepts the --require option to require a file or library" do |
30 | | - Rack::Console.new(require: "json").start |
31 | | - expect { JSON }.not_to raise_error |
32 | | - end |
| 34 | + Rack::Console.new(config: "spec/support/config.ru").start |
| 35 | + end |
33 | 36 |
|
34 | | - it "accepts the --require option to add paths to $LOAD_PATH" do |
35 | | - Rack::Console.new(include: ["lib", "spec"]).start |
36 | | - expect($LOAD_PATH).to include("lib") |
37 | | - expect($LOAD_PATH).to include("spec") |
| 37 | + it "accepts the --require option to require a file or library" do |
| 38 | + Rack::Console.new(require: "json").start |
| 39 | + expect { JSON }.not_to raise_error |
| 40 | + end |
| 41 | + |
| 42 | + it "accepts the --require option to add paths to $LOAD_PATH" do |
| 43 | + Rack::Console.new(include: ["lib", "spec"]).start |
| 44 | + expect($LOAD_PATH).to include("lib") |
| 45 | + expect($LOAD_PATH).to include("spec") |
| 46 | + end |
| 47 | + |
| 48 | + it "accepts the --environment option to set the environment" do |
| 49 | + Rack::Console.new(environment: "production").start |
| 50 | + expect(ENV["RACK_ENV"]).to eq("production") |
| 51 | + end |
38 | 52 | end |
39 | 53 |
|
40 | | - it "accepts an argument to set the environment" do |
41 | | - Rack::Console.new(environment: "production").start |
42 | | - expect(ENV["RACK_ENV"]).to eq("production") |
| 54 | + context "when using Pry" do |
| 55 | + it "accepts the --pry option to enable Pry" do |
| 56 | + expect(IRB).not_to receive(:start) |
| 57 | + expect(Pry).to receive(:start) |
| 58 | + |
| 59 | + Rack::Console.new(pry: true).start |
| 60 | + end |
43 | 61 | end |
44 | 62 |
|
45 | 63 | describe "preamble message" do |
|
0 commit comments