Skip to content

Commit

Permalink
deleted all unnecessary sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Shaydurov committed Nov 23, 2012
1 parent 2b30bcd commit c220845
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 55 deletions.
13 changes: 7 additions & 6 deletions README.md
Expand Up @@ -18,29 +18,30 @@ And then execute:
spec/requests/items_spec.rb:

require 'spec_helper'
describe ItemsController, request_path: '/items' do
describe_request :index, request_path: '/', method: 'GET' do
describe ItemsController do
describe_request :index, request_path: '/items', method: 'GET' do
it 'lists items' do
perform_example_request # same as "get '/items/'"
get '/items'
# ...
end
end

# another style:
describe_request 'GET /:id' do
describe_request 'GET /items/:id' do
it 'shows item' do
perform_example_request id: Item.first.id
get "/items/#{Item.first.id}"
# ...
end
end
end

By default, pending routes will not be output in common spec pass. To show them you should run:

$ RAILS_ENV=test rake spec:requests:with_coverage
$ RAILS_ENV=test bundle exec rake spec:requests:with_coverage

## TODO

0. Make "auto marking" with get/post/put/etc... methods
1. Make untested routes to be marked as pending specs
2. Gem tests :)
3. ?????
Expand Down
6 changes: 2 additions & 4 deletions lib/rspec-routes_coverage.rb
@@ -1,6 +1,5 @@
require 'rspec/rails'
require 'rspec-routes_coverage/dsl'
require 'rspec-routes_coverage/helpers'

module RSpec
module RoutesCoverage
Expand All @@ -23,14 +22,13 @@ def self.remove_pending_route(verb, path)
end

def self.pending_routes?
initialize_routes! if ENV['WITH_ROUTES_COVERAGE'] && !@initialized
self.pending_routes.length > 0
initialize_routes! if ENV['WITH_ROUTES_COVERAGE'] && !self.pending_routes
ENV['WITH_ROUTES_COVERAGE'] && self.pending_routes.length > 0
end

def self.initialize_routes!
::Rails.application.reload_routes!
self.pending_routes = ::Rails.application.routes.routes.routes.clone
@initialized = true
end
end
end
Expand Down
14 changes: 5 additions & 9 deletions lib/rspec-routes_coverage/dsl.rb
Expand Up @@ -2,19 +2,15 @@ module RSpec
module RoutesCoverage
module DSL
def describe_request(*args, &block)
unless args.last.is_a?(Hash) && args.last[:method] && args.last[:request_path]
verb, path = args[0].split ' '
opts = { method: verb, request_path: path }
if args.last.is_a? Hash
args.last.merge! opts
else
args << opts
end
verb, path = if args.last.is_a?(Hash) && args.last[:method] && args.last[:request_path]
[args.last[:method], args.last[:request_path]]
else
args[args[1].is_a?(String) ? 1 : 0].split ' '
end

describe *args do
before :all do
RSpec::RoutesCoverage.remove_pending_route get_example_request_verb, get_example_request_path
RSpec::RoutesCoverage.remove_pending_route verb, path
end if RSpec::RoutesCoverage.pending_routes?

instance_eval(&block) if block
Expand Down
34 changes: 0 additions & 34 deletions lib/rspec-routes_coverage/helpers.rb

This file was deleted.

4 changes: 2 additions & 2 deletions rspec-routes_coverage.gemspec
Expand Up @@ -4,8 +4,8 @@ require File.expand_path('../lib/rspec-routes_coverage/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Andrew Shaydurov"]
gem.email = ["a.shaydurov@roundlake.ru"]
gem.description = %q{TODO: Write a gem description}
gem.summary = %q{TODO: Write a gem summary}
gem.description = %q{This gem allows to specify and track the coverage of tested API requests according to app's routes.}
gem.summary = %q{This gem allows to specify and track the coverage of tested API requests according to app's routes.}
gem.homepage = ""

gem.files = `git ls-files`.split($\)
Expand Down

0 comments on commit c220845

Please sign in to comment.