Ich habe Probleme zu verstehen, wie man mit Rack::Test arbeitet, das Problem, das ich habe, ist mit POST. Dies sind die Klassen und der Fehler:
hellotesting.rb
require 'sinatra'
post '/foo' do
"Hello #{params[:name]}."
end
Das ist der Test:
require 'hellotesting'
require 'test/unit'
require 'rack/test'
set :environment, :test
class HelloWorldTest < Test::Unit::TestCase
def test_it_says_hello_to_you
browser = Rack::Test::Session.new(Rack::MockSession.new(Sinatra::Application))
post "/foo", "name" => "Bryan"
assert browser.last_response.ok?
assert_equal 'Hello Bryan', browser.last_response.body
end
end
Und die Ausgabe:
1) Error:
test_it_says_hello_to_you(HelloWorldTest):
ArgumentError: wrong number of arguments (1 for 0)
/Library/Ruby/Gems/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:1141:in `name'
/Library/Ruby/Gems/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:1141:in `send'
/Library/Ruby/Gems/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:1141:in `compile!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:1141:in `each_pair'
/Library/Ruby/Gems/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:1141:in `compile!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:1129:in `route'
/Library/Ruby/Gems/1.8/gems/sinatra-1.2.6/lib/sinatra/base.rb:1118:in `post'
(__DELEGATE__):3:in `send'
(__DELEGATE__):3:in `post'
testingjeison.rb:11:in `test_it_says_hello_to_you'