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

NoMethodError: undefined method client #167

Closed
einSelbst opened this issue Oct 11, 2014 · 3 comments
Closed

NoMethodError: undefined method client #167

einSelbst opened this issue Oct 11, 2014 · 3 comments

Comments

@einSelbst
Copy link

Hi all,
I think I'm running out of ideas with this. I have installed rspec_api_documentation according to the docs. I'm trying to use it with rails-api.
When I add a test in "spec/acceptance/tools_spec.rb" with the following content:

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

resource "Tools", focus: :true do
  header "Content-Type", "application/json"

  let(:tool) { create(:tool) }

  get "/v1/tools/:id" do
    let(:id) { tool.id}
    example "Show tool with given ID" do
      do_request

      status.should == 200
    end
  end

I tried many variations but I always get

Failure/Error: Unable to find matching line from backtrace
     NoMethodError:
       undefined method `client' for #<RSpec::ExampleGroups::Tools_2::GETV1Tools1:0x007fcfdd69c698>

Why can't it find a "client"? I have seen the "client" mentioned in the gotchas, but I think I don't want to define my own.
I have the following in Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.1.4'
gem 'rails-api'
gem 'pg'
gem 'jbuilder'
gem 'oj'
gem 'oj_mimic_json'
gem 'unicorn'
gem 'rails_12factor', group: :production

group :development do
  gem 'spring'
  gem 'debugger'
end

group :development, :test do
  gem 'spring-commands-rspec'
  gem 'rspec-rails', '~> 3.0.0'
  gem 'guard-rspec'
  gem 'rb-fsevent' if `uname` =~ /Darwin/
  gem 'rspec_api_documentation'
  gem 'apitome'
  gem 'factory_girl_rails'
  gem 'database_cleaner'
  gem 'shoulda-matchers', require: false
  gem 'faker'
end
ruby '2.1.1'

Any hints how to solve this issue would be greatly appreciated.

@einSelbst
Copy link
Author

It's working now, but I have no idea why.

@einSelbst
Copy link
Author

I see. The problem was in my helper I had used (all) the Configuration options listed in the Readme and assumed that # Values listed are the default values means it would be safe to just use them as is. Turned out I had to comment out the line:

config.client_method = :client

Of course, now the error message makes sense and I actually had looked at that line and the accompanying comment without realizing. Maybe it should be commented out by default in this example file.

@oestrich
Copy link
Contributor

So the problem was how setting that option specifically works. It defines a new alias method and then undefs the original. So it defined an alias to client named client then undefed client. https://github.com/zipmark/rspec_api_documentation/blob/master/lib/rspec_api_documentation/configuration.rb#L98-L99

I'm not sure this is a problem because they're the defaults and you shouldn't have to copy any of them in order for the configuration to kick in. If you want to make a PR for the setter method skipping the module eval if the value didn't change I'd accept it.

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

2 participants