diff --git a/.gitignore b/.gitignore index a2e6bd4..45bd856 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ doc/ +vendor/bundle/ +.bundle/ diff --git a/spec/hanami_example_spec.rb b/spec/hanami_example_spec.rb new file mode 100644 index 0000000..8c9071d --- /dev/null +++ b/spec/hanami_example_spec.rb @@ -0,0 +1,37 @@ +require 'rack/test' +require 'rack/builder' + +describe 'HanamiExample' do + include Rack::Test::Methods + + def app + # Load the actual app + ru_path = File.join(File.dirname(__FILE__), '../hanami_routing/hanami_routing.ru') + actual_app = Rack::Builder.parse_file(ru_path) + + # Create a wrapper that sets REQUEST_PATH from PATH_INFO + lambda do |env| + env['REQUEST_PATH'] = env['PATH_INFO'] + actual_app.call(env) + end + end + + it 'responds to GET /' do + get '/' + expect(last_response.status).to eq(200) + expect(last_response.body).to match(/Hello, from index.html/) + expect(last_response.body).to match(/Say hi to Jordan<\/a>/) + end + + it 'responds to GET /:name' do + get '/jordan' + expect(last_response.status).to eq(200) + expect(last_response.body).to match(/Hello, jordan!/) + end + + it 'returns 404 for unknown routes' do + get '/path/with/multiple/segments' + expect(last_response.status).to eq(404) + expect(last_response.body).to match(/404 Not Found/) + end +end \ No newline at end of file diff --git a/spec/sinatra_example_spec.rb b/spec/sinatra_example_spec.rb new file mode 100644 index 0000000..97d53c3 --- /dev/null +++ b/spec/sinatra_example_spec.rb @@ -0,0 +1,37 @@ +require 'rack/test' +require 'rack/builder' + +describe 'SinatraExample' do + include Rack::Test::Methods + + def app + # Load the actual app + ru_path = File.join(File.dirname(__FILE__), '../sinatra_routing/sinatra_routing.ru') + actual_app = Rack::Builder.parse_file(ru_path) + + # Create a wrapper that sets REQUEST_PATH from PATH_INFO + lambda do |env| + env['REQUEST_PATH'] = env['PATH_INFO'] + actual_app.call(env) + end + end + + it 'responds to GET /' do + get '/' + expect(last_response.status).to eq(200) + expect(last_response.body).to match(/Hello, from index.html/) + expect(last_response.body).to match(/Say hi to Jordan<\/a>/) + end + + it 'responds to GET /:name' do + get '/jordan' + expect(last_response.status).to eq(200) + expect(last_response.body).to match(/Hello, jordan!/) + end + + it 'returns 404 for unknown routes' do + get '/path/with/multiple/segments' + expect(last_response.status).to eq(404) + expect(last_response.body).to match(/404 Not Found/) + end +end \ No newline at end of file