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

Change default path for load routes #43

Closed
wants to merge 1 commit into from
Closed

Change default path for load routes #43

wants to merge 1 commit into from

Conversation

ildarkayumov
Copy link

This changes to fix this error:

../api_tasters/posts.rb:1:in `<top (required)>': uninitialized constant ApiTaster (NameError)

This error is appear, when we run rspec, when in gemfile we did not include gem 'api_taster' to test group.

@ildarkayumov
Copy link
Author

Have you any questions to this pull request?

@fredwu
Copy link
Owner

fredwu commented Jun 11, 2013

@ildarkayumov Thanks for the PR. Do you mind posting a bit background info on this? i.e. How do you get this error in the first place? It looks like a file loading issue to me.

@ildarkayumov
Copy link
Author

@fredwu I put gem 'api_taster' to my Gemfile so:

group :development, :staging do
  gem 'api_taster', git: '[email protected]:fredwu/api_taster.git'
end

When i run my tests with command: rspec, terminal returns this error:

Rack::File headers parameter replaces cache_control after Rack 1.5.
/home/timurb/projects/rails3-base-api/app/api_tasters/posts.rb:1:in `<top (required)>': uninitialized constant ApiTaster (NameError)
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in `each'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:438:in `block in eager_load!'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:436:in `each'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/engine.rb:436:in `eager_load!'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/timurb/projects/rails3-base-api/config/environment.rb:5:in `<top (required)>'
    from /home/timurb/projects/rails3-base-api/spec/spec_helper.rb:6:in `require'
    from /home/timurb/projects/rails3-base-api/spec/spec_helper.rb:6:in `<top (required)>'
    from /home/timurb/projects/rails3-base-api/spec/api/posts_spec.rb:1:in `require'
    from /home/timurb/projects/rails3-base-api/spec/api/posts_spec.rb:1:in `<top (required)>'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in `load'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in `each'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.13.0/lib/rspec/core/configuration.rb:819:in `load_spec_files'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.13.0/lib/rspec/core/command_line.rb:22:in `run'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:80:in `run'
    from /home/timurb/projects/rails3-base-api/vendor/bundle/ruby/1.9.1/gems/rspec-core-2.13.0/lib/rspec/core/runner.rb:17:in `block in autorun'
Coverage report generated for RSpec to /home/timurb/projects/rails3-base-api/coverage. 24 / 37 LOC (64.86%) covered.

But if we include gem to test group(its not good idea), its work fine. And now, if we change location of folder api_tasters to libs/api_tasters, it works too.

@ildarkayumov
Copy link
Author

Rspec is try to load "/app" folder and see so code:

ApiTaster.routes do
  get '/posts'
end

He is return this error, because he didn't know what is ApiTaster.

@fredwu
Copy link
Owner

fredwu commented Jun 13, 2013

Looks to me that require "api_taster" is needed perhaps in spec_helper.rb?

@ildarkayumov
Copy link
Author

No, it doesn't help. And we do not have to test ApiTaster- files, i think, require "api_taster" - it would be superfluous...

@ildarkayumov
Copy link
Author

Now, if developer wants to load ApiTaster-routes from "/app/api_tasters", he can init this code in initialize-file config / initializers / api_taster.rb :

ApiTaster::Route.path = "#{Rails.root}/app/api_tasters"

@ildarkayumov
Copy link
Author

Maybe, folder "lib/api_tasters" is not good place for this files?

@ildarkayumov
Copy link
Author

@fredwu Why do not you merge this pull request?

@fredwu
Copy link
Owner

fredwu commented Jul 18, 2013

Hi @ildarkayumov I really appreciate your PR! Thanks for your work! I have taken a brief look at this as well as #45 and I believe #45 is a slightly cleaner approach so I am closing this one in favour of #45. :)

@fredwu fredwu closed this Jul 18, 2013
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

Successfully merging this pull request may close these issues.

2 participants