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

how does the the test works? #1683

Closed
funal125 opened this Issue May 20, 2014 · 8 comments

Comments

Projects
None yet
4 participants
@funal125
Contributor

funal125 commented May 20, 2014

I initialized a new project with padrino 0.12.2 and chose minitest as my test framework. But i am very confused with the test behavior.
I create a new controller, and run the test.

$ padrino g controller user
$ rake test

it fail with

Techcomm::App::UserHelper#test_0001_should return nil:
NameError: uninitialized constant Techcomm::App::UserHelper

And then i create another project with test frame work spec to test the situation. i do the same procedure, It fail but give me different message.

Failure/Error: expect(subject.foo).to be_nil
NoMethodError:
undefined method `foo' for #<Class:0x007f29a71efaf0>

With Rspec, It can find the constant Techcomm::App::UserHelper.

And then i run the spec separately.

$ bundle exec rspec ./spec/app/helpers/base_helper_spec.rb
  1) Booking::App::BaseHelper should return nil
     Failure/Error: before { helpers.extend Booking::App::BaseHelper }
     NameError:
       uninitialized constant Booking::App::BaseHelper

It cant find the constant Booking::App::BaseHelper, the same with minitest.

And then

$ bundle exec rspec ./spec/app/helpers/base_helper_spec.rb ./spec/app/controllers/base_controller_spec.rb
     Failure/Error: expect(subject.foo).to be_nil
     NoMethodError:
       undefined method `foo' for #<Class:0x007f8ae835fed8>

It found the constant Booking::App::BaseHelper !!!

Why?? I cant understand what happened.

@nesquena nesquena added this to the 0.12.3 milestone May 20, 2014

@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena May 20, 2014

Member

Looks like we might have borked the test generators in the last release. Would you be able to install 0.12.1 and verify that test generation works as expected?

Member

nesquena commented May 20, 2014

Looks like we might have borked the test generators in the last release. Would you be able to install 0.12.1 and verify that test generation works as expected?

@funal125

This comment has been minimized.

Show comment
Hide comment
@funal125

funal125 May 20, 2014

Contributor

Ok, i will test it.

Contributor

funal125 commented May 20, 2014

Ok, i will test it.

@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka May 20, 2014

Member

Hmm.
I couldn't reproduce.
The second message is not problem because it is provided as a sample test code.

Member

namusyaka commented May 20, 2014

Hmm.
I couldn't reproduce.
The second message is not problem because it is provided as a sample test code.

@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka May 20, 2014

Member

Ah, confirmed.
This problem seems to be caused by the minitest feature.
Therefore, this problem occurs randomly.
If did not execute get "/" in controller test file, the test application haven't load helper files yet.

Member

namusyaka commented May 20, 2014

Ah, confirmed.
This problem seems to be caused by the minitest feature.
Therefore, this problem occurs randomly.
If did not execute get "/" in controller test file, the test application haven't load helper files yet.

@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka May 20, 2014

Member

@felix125 Quick fix:

  before do
    get "/" # <-- add this
    @helpers = Class.new
    @helpers.extend Techcomm::App::UserHelper
  end
Member

namusyaka commented May 20, 2014

@felix125 Quick fix:

  before do
    get "/" # <-- add this
    @helpers = Class.new
    @helpers.extend Techcomm::App::UserHelper
  end
@funal125

This comment has been minimized.

Show comment
Hide comment
@funal125

funal125 May 20, 2014

Contributor

@nesquena Thanks, it work for me.

Contributor

funal125 commented May 20, 2014

@nesquena Thanks, it work for me.

@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka May 20, 2014

Member

@padrino/core-members I guess these patches fix this problem, but I want to find better solution.

# test/app/helpers/user_helper_test.rb
before do
  get "/" unless defined?(Techcomm::App::UserHelper) # <- Add this
  @helpers = Class.new
  @helpers.extend Techcomm::App::UserHelper
end

or

# test/test_config.rb
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path('../../config/boot', __FILE__)

Padrino.application # <- Add this

class MiniTest::Spec
  include Rack::Test::Methods
Member

namusyaka commented May 20, 2014

@padrino/core-members I guess these patches fix this problem, but I want to find better solution.

# test/app/helpers/user_helper_test.rb
before do
  get "/" unless defined?(Techcomm::App::UserHelper) # <- Add this
  @helpers = Class.new
  @helpers.extend Techcomm::App::UserHelper
end

or

# test/test_config.rb
RACK_ENV = 'test' unless defined?(RACK_ENV)
require File.expand_path('../../config/boot', __FILE__)

Padrino.application # <- Add this

class MiniTest::Spec
  include Rack::Test::Methods

@ujifgc ujifgc added test labels May 20, 2014

@namusyaka namusyaka closed this in a60f2e8 Jul 1, 2014

ujifgc added a commit that referenced this issue Jul 1, 2014

Merge pull request #1689 from padrino/fix-tests
Test should not depend on the execution order, fixes #1683
@namusyaka

This comment has been minimized.

Show comment
Hide comment
@namusyaka

namusyaka Jul 1, 2014

Member

@felix125 I'm sorry for the late response.
The issue was fixed by loading helper files in advance. see a60f2e8
Let me know if you need anything.
Thank you.

Member

namusyaka commented Jul 1, 2014

@felix125 I'm sorry for the late response.
The issue was fixed by loading helper files in advance. see a60f2e8
Let me know if you need anything.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment