forked from amatsuda/traceroute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaml_test.rb
170 lines (128 loc) · 4.22 KB
/
yaml_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# frozen_string_literal: true
require_relative 'test_helper'
module JasmineRails
class SpecRunner < ApplicationController; end
end
module YamlTestsCondition
def setup
super
JasmineRails::SpecRunner.class_eval { def index() end }
end
def teardown
super
JasmineRails::SpecRunner.send :undef_method, :index
JasmineRails::SpecRunner.clear_action_methods!
end
end
class DotFileTest < Minitest::Test
prepend YamlTestsCondition
def setup
File.open ".traceroute.yaml", "w" do |file|
file.puts 'ignore_unreachable_actions:'
file.puts '- ^jasmine_rails\/'
file.puts 'ignore_unused_routes:'
file.puts '- ^users'
end
DummyApp::Application.routes.draw do
resources :users, :only => [:index, :show, :new, :create]
namespace :admin do
resources :shops, :only => :index
end
namespace :api do
resources :books, :only => :index
end
end
@traceroute = Traceroute.new Rails.application
end
def teardown
DummyApp::Application.routes.clear!
File.delete ".traceroute.yaml"
end
def test_unreachable_actions_are_ignored
refute @traceroute.defined_action_methods.include? 'jasmine_rails/spec_runner#index'
end
def test_used_routes_are_ignored
assert_routed_actions 'admin/shops#index', 'api/books#index'
end
end
class EmptyFileTest < Minitest::Test
prepend YamlTestsCondition
def setup
File.open ".traceroute.yaml", "w" do |file|
end
DummyApp::Application.routes.draw do
resources :users, :only => [:index, :show, :new, :create]
namespace :admin do
resources :shops, :only => :index
end
namespace :api do
resources :books, :only => :index
end
end
@traceroute = Traceroute.new Rails.application
end
def teardown
DummyApp::Application.routes.clear!
File.delete ".traceroute.yaml"
end
def test_empty_yaml_file_is_handled_the_same_as_no_file
assert_defined_action_methods 'users#index', 'users#show', 'users#index2', 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'jasmine_rails/spec_runner#index'
end
def test_property_with_no_key
assert_routed_actions 'admin/shops#index', 'api/books#index', 'users#index', 'users#show', 'users#new', 'users#create'
end
end
class InvalidFileTest < Minitest::Test
prepend YamlTestsCondition
def setup
File.open ".traceroute.yml", "w" do |file|
file.puts 'ignore_unreachable_actions:'
file.puts 'ignore_unused_routes:'
end
DummyApp::Application.routes.draw do
resources :users, :only => [:index, :show, :new, :create]
namespace :admin do
resources :shops, :only => :index
end
namespace :api do
resources :books, :only => :index
end
end
@traceroute = Traceroute.new Rails.application
end
def teardown
DummyApp::Application.routes.clear!
File.delete ".traceroute.yml"
end
def test_empty_yaml_file_is_handled_the_same_as_no_file
assert_defined_action_methods 'users#index', 'users#show', 'users#index2', 'admin/shops#create', 'admin/shops#index', 'api/books#create', 'api/books#index', 'jasmine_rails/spec_runner#index'
end
def test_property_with_no_key
assert_routed_actions 'admin/shops#index', 'api/books#index', 'users#index', 'users#show', 'users#new', 'users#create'
end
end
class FilenameSupportTest < Minitest::Test
prepend YamlTestsCondition
def test_yml_supported
File.open ".traceroute.yml", "w" do |file|
file.puts 'ignore_unreachable_actions:'
file.puts '- ^jasmine_rails\/'
file.puts 'ignore_unused_routes:'
file.puts '- ^users'
end
@traceroute = Traceroute.new Rails.application
refute @traceroute.defined_action_methods.include? 'jasmine_rails/spec_runner#index'
File.delete ".traceroute.yml"
end
def test_no_extension_supported
File.open ".traceroute", "w" do |file|
file.puts 'ignore_unreachable_actions:'
file.puts '- ^jasmine_rails\/'
file.puts 'ignore_unused_routes:'
file.puts '- ^users'
end
@traceroute = Traceroute.new Rails.application
refute @traceroute.defined_action_methods.include? 'jasmine_rails/spec_runner#index'
File.delete ".traceroute"
end
end