rspec-routes_coverage 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -57,9 +57,19 @@ Alternatively you can run the following Rake task (ships with the gem):
57
57
 
58
58
  $ rake spec:requests:coverage
59
59
 
60
- ## TODO
60
+ ## Excluding routes
61
61
 
62
- * Add the possibility to exclude some routes/namespaces from coverage analysis
62
+ To skip routes you are not going to test you can use the following options:
63
+
64
+ ```ruby
65
+ RSpec.configure do |config|
66
+ config.routes_coverage.exclude_namespaces = %w(back)
67
+ config.routes_coverage.exclude_routes = [
68
+ /GET \//,
69
+ /POST \/sessions.*/
70
+ ]
71
+ end
72
+ ```
63
73
 
64
74
  ## Contributing
65
75
 
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module RoutesCoverage
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -14,6 +14,7 @@ module RSpec
14
14
  end
15
15
 
16
16
  mattr_accessor :pending_routes
17
+ mattr_accessor :excluded_routes
17
18
  mattr_accessor :auto_tested_routes
18
19
  mattr_accessor :manually_tested_routes
19
20
  mattr_accessor :tested_routes_num
@@ -47,22 +48,38 @@ module RSpec
47
48
  return if self.pending_routes
48
49
 
49
50
  ::Rails.application.reload_routes!
50
- self.pending_routes = ::Rails.application.routes.routes.routes.clone
51
51
 
52
+ self.pending_routes = ::Rails.application.routes.routes.routes.clone
53
+ self.excluded_routes = []
54
+ self.auto_tested_routes = []
55
+ self.manually_tested_routes = []
56
+
57
+ # Skip config.exclude_routes
58
+ unless RSpec.configuration.routes_coverage.exclude_routes.blank?
59
+ selector = Regexp.union(*RSpec.configuration.routes_coverage.exclude_routes)
60
+ self.pending_routes.select! do |x|
61
+ keep = ("#{x.verb.to_s[8..-3]} #{x.path.spec}".strip =~ selector).nil?
62
+ self.excluded_routes << x unless keep
63
+ keep
64
+ end
65
+ end
66
+
67
+ # Skip config.exclude_namespaces
52
68
  selector = []
53
69
  selector += RSpec.configuration.routes_coverage.exclude_namespaces.map do |n|
54
70
  "^/#{n}/"
55
71
  end
56
-
57
72
  unless selector.blank?
58
73
  selector = /(#{selector.join(')|(')})/
59
- self.pending_routes.select!{|x| (x.path.spec.to_s =~ selector).nil?}
74
+ self.pending_routes.select! do |x|
75
+ keep = (x.path.spec.to_s =~ selector).nil?
76
+ self.excluded_routes << x unless keep
77
+ keep
78
+ end
60
79
  end
61
80
 
62
- self.routes_num = ::Rails.application.routes.routes.routes.length
63
- self.tested_routes_num = self.pending_routes.length
64
- self.auto_tested_routes = []
65
- self.manually_tested_routes = []
81
+ self.routes_num = ::Rails.application.routes.routes.routes.length
82
+ self.tested_routes_num = self.pending_routes.length
66
83
  end
67
84
  end
68
85
  end
@@ -97,7 +114,14 @@ RSpec.configure do |config|
97
114
  end
98
115
 
99
116
  if ENV['LIST_ROUTES_COVERAGE']
100
- { green: :manually_tested_routes, blue: :auto_tested_routes, yellow: :pending_routes }.each do |color, name|
117
+ legend = {
118
+ magenta: :excluded_routes,
119
+ green: :manually_tested_routes,
120
+ blue: :auto_tested_routes,
121
+ yellow: :pending_routes
122
+ }
123
+
124
+ legend.each do |color, name|
101
125
  puts "\n\n"
102
126
  puts "#{name.to_s.humanize} (#{RSpec::RoutesCoverage.send(name).length}/#{RSpec::RoutesCoverage.routes_num})".send(color).bold
103
127
  puts "\n"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-routes_coverage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-11-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-rails
17
- requirement: &70339426417820 !ruby/object:Gem::Requirement
17
+ requirement: &70107171042560 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70339426417820
25
+ version_requirements: *70107171042560
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: colored
28
- requirement: &70339426417180 !ruby/object:Gem::Requirement
28
+ requirement: &70107171041200 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70339426417180
36
+ version_requirements: *70107171041200
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: actionpack
39
- requirement: &70339426416540 !ruby/object:Gem::Requirement
39
+ requirement: &70107171055680 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70339426416540
47
+ version_requirements: *70107171055680
48
48
  description: Rails-RSpec plugin that will track the coverage of routes among your
49
49
  request specs
50
50
  email: