0
votes

I'm practicing the Ruby on Rails Tutorial, and I have a question about rspec.

When testing the method full_title defined in app/helpers/application_helper.rb,

module ApplicationHelper
    def full_title(title)
        base_title = "Ruby on Rails Tutorial Sample App"
        if title.empty?
            base_title
        else
           "#{base_title} | #{title}"
        end
    end # end of def
end

you don't have to include ApplicationHelper in spec/helpers/application_helper_spec.rb. While in the spec/requests/static_pages_spec.rb, you have to include ApplicationHelper, otherwise the test will be failed for undefined methodfull_title'`.

In my opinion, rspec will autoload file app/helpers/application_helper.rb, and you don't have to include it again. What's the difference of the two test example?

1

1 Answers

1
votes

That has nothing to do with "autoloading" which is a different thing in the rails context.

RSpec uses the Rails test-framework under the hood that you find in classes like ActionController::TestCase.

Those helper classes setup a whole bunch of stuff to provide a Rails environment for testing.

Since there are different kinds of environments like unit, functional and integration, different setups occur. That is why you have to handle stuff differently for different groups of spec.