Reputation: 96484
I have a Sinatra application.
it includes the following:
helpers do
def helper1
...code...
end
def helper2
...code...
end
...
end
How can I test these helper methods?
Currently my rspec has:
ENV['RACK_ENV'] = 'test'
require_relative '../app' # <-- your sinatra app
describe 'Basic test' do
before :each do
@xml_info = File.read('examples/request_litle_auth.xml')
end
it "basic test" do
'a'.should eq 'a'
end
it "can call a helper method" do
to_dollars(30)
end
end
but that gives:
undefined method `to_dollars' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000002460e18>
Upvotes: 1
Views: 769
Reputation: 18845
classical sinatra testing works with Rack::Test
. this is a fake browser session that performs requests against your sinatra application, so that you can assert response codes, content etc.
if you want to test a custom defined helper method, you will need to something similar to this: https://github.com/padrino/padrino-framework/issues/930
TL;DR
create a module, include it in your helper call, test the module in any fashion you like.
Upvotes: 1