fredwu / api_taster

A quick and easy way to visually test your Rails application's API.
http://fredwu.github.com/api_taster
727 stars 85 forks source link

Change default path for load routes #43

Closed ildarkayumov closed 11 years ago

ildarkayumov commented 11 years ago

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 commented 11 years ago

Have you any questions to this pull request?

fredwu commented 11 years ago

@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 commented 11 years ago

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

group :development, :staging do
  gem 'api_taster', git: 'git@github.com: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 commented 11 years ago

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 commented 11 years ago

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

ildarkayumov commented 11 years ago

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

ildarkayumov commented 11 years ago

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 commented 11 years ago

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

ildarkayumov commented 11 years ago

@fredwu Why do not you merge this pull request?

fredwu commented 11 years ago

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. :)