Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined method `route' for RSpec::Core::Example #222

Closed
nickgnd opened this issue Aug 24, 2015 · 4 comments
Closed

Undefined method `route' for RSpec::Core::Example #222

nickgnd opened this issue Aug 24, 2015 · 4 comments

Comments

@nickgnd
Copy link

nickgnd commented Aug 24, 2015

Hi, I'm trying to generate the api documentation of the web app that I'm working on.
I've followed the instructions step by step, but when I run the task: bin/rake api:docs:generate

Before it lists all my expectations:

/Users/nico/.rvm/rubies/ruby-2.2.0/bin/ruby -I/Users/nico/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/lib:/Users/nico/.rvm/gems/ruby-2.2.0/gems/rspec-support-3.2.2/lib /Users/nico/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.3/exe/rspec --pattern spec/api/\*\*/\*_spec.rb --format RspecApiDocumentation::ApiFormatter
Generating API Docs
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 44647
  Sessions
  Api::V1::SessionsController
  Try login with authentication token - through API
    * should respond with 401
    ...
    ...
    ...

After that, it raises this exception:

/Users/nico/.rvm/gems/ruby-2.2.0/gems/rspec_api_documentation-4.4.0/lib/rspec_api_documentation/example.rb:14:in `method_missing': undefined method `route' for #<RSpec::Core::Example:0x007ffd36c261c8> (NoMethodError)

It seems that is missing the method route in RSpec Core library.
So I look into the RSpec Core docs and I don't found any method called route.
http://www.rubydoc.info/github/rspec/rspec-core/RSpec/Core/Example

Maybe there is a problem with the older version of RSpec::Core? I'm using the 3.2 version, but is available the v3.3. Or maybe is a problem with my spec or configuration?

I'm available for other details.


My dev environment from Gemfile.lock:

  • rails 4.2.0 (on Ruby 2.2.0)
  • rspec-rails (3.2.1)
    • rspec-core (~> 3.2.0)
    • rspec-expectations (~> 3.2.0)
    • rspec-mocks (~> 3.2.0)
    • rspec-support (~> 3.2.0)
  • rspec-support (3.2.2)
  • rspec_api_documentation (4.4.0)

my api_documentation_helper file:

require 'rails_helper'
require 'rspec_api_documentation'
require 'rspec_api_documentation/dsl'

RspecApiDocumentation.configure do |config|
   config.format = [:json, :html]
  config.curl_host = 'http://localhost:3000'
  config.api_name = "API Contact APP"
end

my personal task file (it looks under ./spec/api/ folder):

require 'rspec/core/rake_task'

namespace :api do

    desc 'Generate API request documentation from API specs'
    RSpec::Core::RakeTask.new('docs:generate') do |t|
      t.pattern = 'spec/api/**/*_spec.rb'
      t.rspec_opts = ["--format RspecApiDocumentation::ApiFormatter"]
    end

    desc 'Generate API request documentation from API specs (ordered)'
    RSpec::Core::RakeTask.new('docs:generate:ordered') do |t|
      t.pattern = 'spec/api/**/*_spec.rb'
      t.rspec_opts = ["--format RspecApiDocumentation::ApiFormatter", "--order default"]
    end
end 

my spec file under api folder looks like:

require 'rails_helper'
require 'api_documentation_helper'

RSpec.describe Api::V1::SessionsController, type: :controller  do

  resource 'Sessions' do

  # Default user
  let(:user) { create(:user) }

  describe "POST #create - login through API" do
    #...
  end

  describe "DELETE #destroy - through API" do
   #...
  end

 #...

   end
 end
end
@nickgnd nickgnd closed this as completed Aug 25, 2015
@hut8
Copy link

hut8 commented Sep 19, 2015

@nickgnd How did you fix this? I'm running into the same thing.

@oestrich
Copy link
Contributor

Looking through this, I don't see a get/post block. That sets up the route required. If you scan through the README or the example app you can see examples of it in use.

@hut8
Copy link

hut8 commented Sep 19, 2015

@oestrich Thanks for the quick reply. I have a full suite of request tests for my API, and I was hoping I could just basically move my spec/requests into spec/acceptance, add the require 'rspec_api_documentation/dsl' line and have things work. But it looks like these are completely different than that, right?

@oestrich
Copy link
Contributor

These are very different from what you wrote in spec/requests. You need to use the DSL (or write a lot of metadata) in order for RAD to perform it's job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants