- Rails 5.0.0.rc1
- rspec-core@a99ff26
- rspec-rails@052206f
I have a controller spec that looks roughly like this:
require "rails_helper"
RSpec.describe InquiriesController, type: :controller do
describe "#create" do
let(:inquiry_attributes) { attributes_for(:inquiry) }
before do
post :create, inquiry: inquiry_attributes
end
it "whatever" do
expect(2).to be 2
end
end
end
This lives in spec/controllers/inquiries_controller_spec.rb, so RSpec should not be inferring that it's a request spec based on its location.
When I run this spec, I get the following error:
1) InquiriesController#create whatever
Failure/Error: post :create, inquiry: inquiry_attributes
URI::InvalidURIError:
bad URI(is not URI?): create
# /Users/spetryk/.gem/ruby/2.3.1/gems/rack-test-0.6.3/lib/rack/test.rb:193:in `env_for'
# /Users/spetryk/.gem/ruby/2.3.1/gems/rack-test-0.6.3/lib/rack/test.rb:66:in `post'
Hmm, it seems that post is coming from Rack. Not sure why. Here's my spec_helper and rails_helper:
spec_helper.rb
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
rails_helper.rb
ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../../config/environment", __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require "spec_helper"
require "rspec/rails"
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.use_transactional_fixtures = true
# Yes, I've tried removing this line
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
config.include Rails.application.routes.url_helpers
config.include FactoryGirl::Syntax::Methods
end
My InquiriesController lives in app/controllers/inquiries_controller.rb, is not underneath a module, and the route is wired up correctly (I verified this by manually visiting it and verifying that it works). The method is indeed named create and I've done this successfully with other projects.
:createto/inquiriesmakes the spec pass. - Steven Petryk