Skip to content

Commit f64dba8

Browse files
committed
fix flaking tests
routes related tests were failing for two reasons: - order dependencies between tests utilizing routes.rb and tests utilizing in file routes. - automatically reloading routes at the top of process. The routes file is always loaded by rails, so I think removing the thing should be good. Tests still work anyways.
1 parent 781f26d commit f64dba8

File tree

5 files changed

+23
-39
lines changed

5 files changed

+23
-39
lines changed

lib/pry-rails/commands/show_routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def options(opt)
1414
end
1515

1616
def process
17-
Rails.application.reload_routes!
1817
all_routes = Rails.application.routes.routes
1918

2019
formatted =

spec/config/environment.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ class Pokemon < ActiveRecord::Base
6565
has_many :beers, :through => :hacker
6666
end
6767

68+
CarsController = Class.new(ActionController::Base)
69+
module Admin
70+
CarsController = Class.new(ActionController::Base)
71+
TrucksController = Class.new(ActionController::Base)
72+
end
73+
6874
if defined?(Mongoid)
6975
class Artist
7076
include Mongoid::Document

spec/config/routes.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
TestApp.routes.draw do
22
resource :pokemon, :beer
3+
resources :cars
4+
namespace :admin do
5+
resources :cars
6+
resources :trucks
7+
end
8+
39
get 'exit' => proc { exit! }
410
get 'pry' => proc { binding.pry; [200, {}, ['']] }
11+
root to: 'cars#index'
512
end

spec/find_route_spec.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,14 @@
33
require 'spec_helper'
44

55
describe "find-route" do
6-
before do
7-
routes = Rails.application.routes
8-
routes.draw {
9-
namespace :admin do
10-
resources :users
11-
resources :images
12-
end
13-
}
14-
routes.finalize!
15-
end
16-
176
it 'returns the route for a single action' do
18-
output = mock_pry('find-route Admin::UsersController#show', 'exit-all')
7+
output = mock_pry('find-route Admin::CarsController#show', 'exit-all')
198
_(output).must_match(/show GET/)
209
_(output).wont_match(/index GET/)
2110
end
2211

2312
it 'returns all the routes for a controller' do
24-
output = mock_pry('find-route Admin::UsersController', 'exit-all')
13+
output = mock_pry('find-route Admin::CarsController', 'exit-all')
2514
_(output).must_match(/index GET/)
2615
_(output).must_match(/show GET/)
2716
_(output).must_match(/new GET/)
@@ -33,8 +22,8 @@
3322

3423
it 'returns all routes for controllers under a namespace' do
3524
output = mock_pry('find-route Admin', 'exit-all')
36-
_(output).must_match(/Routes for Admin::UsersController/)
37-
_(output).must_match(/Routes for Admin::ImagesController/)
25+
_(output).must_match(/Routes for Admin::CarsController/)
26+
_(output).must_match(/Routes for Admin::TrucksController/)
3827
end
3928

4029
it 'returns no routes found when controller is not recognized' do

spec/recognize_path_spec.rb

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,6 @@
33
require 'spec_helper'
44

55
describe "recognize-path" do
6-
before do
7-
FooController = Class.new(ActionController::Base)
8-
BoomsController = Class.new(ActionController::Base)
9-
routes = Rails.application.routes
10-
routes.draw {
11-
root(:to => 'foo#index', :constraints => {:host => 'example.com'})
12-
resources :booms
13-
}
14-
routes.finalize!
15-
end
16-
17-
after do
18-
[:FooController, :BoomsController].each { |const|
19-
Object.__send__(:remove_const, const)
20-
}
21-
end
22-
236
it 'fails gracefully if no path is given' do
247
output = mock_pry('recognize-path', 'exit-all')
258
_(output).must_match \
@@ -28,25 +11,25 @@
2811

2912
it "prints info about controller/action that is bound to the given path" do
3013
output = mock_pry('recognize-path example.com', 'exit-all')
31-
_(output).must_match(/controller.+foo/)
14+
_(output).must_match(/controller.+cars/)
3215
_(output).must_match(/action.+index/)
3316
end
3417

3518
it "accepts short path" do
36-
output = mock_pry('recognize-path /booms/1/edit', 'exit-all')
19+
output = mock_pry('recognize-path /cars/1/edit', 'exit-all')
3720
_(output).must_match(/action.+edit/)
38-
_(output).must_match(/controller.+booms/)
21+
_(output).must_match(/controller.+cars/)
3922
_(output).must_match(/id.+1/)
4023
end
4124

4225
it "accepts -m switch" do
43-
output = mock_pry('recognize-path example.com/booms -m post', 'exit-all')
44-
_(output).must_match(/controller.+booms/)
26+
output = mock_pry('recognize-path example.com/cars -m post', 'exit-all')
27+
_(output).must_match(/controller.+cars/)
4528
_(output).must_match(/action.+create/)
4629
end
4730

4831
it "doesn't accept unknown methods" do
49-
output = mock_pry('recognize-path example.com/booms -m posty', 'exit-all')
32+
output = mock_pry('recognize-path example.com/cars -m posty', 'exit-all')
5033
_(output).must_match 'Unknown HTTP method: posty'
5134
end
5235

0 commit comments

Comments
 (0)