I’ve searched a bit but I can’t find a good explanation about it so here is my question.
I’m writing a Rails engine that only adds helpers.
The structure is like this (the important part):
my_engine/
-- app/
-- helpers/
-- my_engine/
-- my_engine_helper.rb
-- spec/
-- dummy/
-- spec_helper.rb
My spec_helper.rb is the following:
# Configure Rails Envinronment
ENV['RAILS_ENV'] = 'test'
require File.expand_path('../dummy/config/environment.rb', __FILE__)
require 'rspec/rails'
ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[File.join(ENGINE_RAILS_ROOT, 'spec/support/**/*.rb')].each { |f| require f }
RSpec.configure do |config|
config.use_transactional_fixtures = true
end
So far so good, but I’m not sure about how to test my helper.
I would like to know what is the best way to:
- organize the test files
- test that the dummy app can use the helper
- test the helper itself
For now I get the following error when running the spec:
undefined local variable or method `helper' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fcee8b0f4a0>
with the following test:
require 'spec_helper'
module MyEngine
describe MyEngineHelper do
describe '#something' do
it "does something" do
helper.something.should be_true
end
end
end
end
Thank you !
Move it to
spec/helpers/my_engine_helper_spec.rb. Therspec-railshas a hook for things inspec/helpersto add thehelpermethod.