Skip to content

Commit

Permalink
RSpec cleanup. Ref #144
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Apr 10, 2017
1 parent 8299d5a commit 51017aa
Show file tree
Hide file tree
Showing 36 changed files with 894 additions and 881 deletions.
1 change: 0 additions & 1 deletion Rakefile
Expand Up @@ -11,7 +11,6 @@ end
namespace :spec do
RSpec::Core::RakeTask.new(:unit) do |task|
file_list = FileList['spec/**/*_spec.rb']
file_list = file_list.exclude("spec/{integration,isolation}/**/*_spec.rb")

task.pattern = file_list
end
Expand Down
141 changes: 0 additions & 141 deletions spec/benchmarks/named_routes_spec.rb

This file was deleted.

@@ -1,19 +1,19 @@
RSpec.describe 'Body parsing' do
before do
endpoint = ->(env) {
endpoint = lambda { |env|
[200, {}, [env['router.params'].inspect]]
}

@routes = Hanami::Router.new(parsers: [:json, XmlParser.new]) {
@routes = Hanami::Router.new(parsers: [:json, XmlParser.new]) do
patch '/books/:id', to: endpoint
patch '/authors/:id', to: endpoint
}
end

@app = Rack::MockRequest.new(@routes)
end

it 'is successful (JSON)' do
body = StringIO.new( %({"published":"true"}).encode(Encoding::ASCII_8BIT) )
body = StringIO.new(%({"published":"true"}).encode(Encoding::ASCII_8BIT))
response = @app.patch('/books/23', 'CONTENT_TYPE' => 'application/json', 'rack.input' => body, lint: true)

expect(response.status).to eq(200)
Expand All @@ -22,15 +22,15 @@

# See https://github.com/hanami/router/issues/124
it 'does not overrides URI params' do
body = StringIO.new( %({"id":"1"}).encode(Encoding::ASCII_8BIT) )
body = StringIO.new(%({"id":"1"}).encode(Encoding::ASCII_8BIT))
response = @app.patch('/books/23', 'CONTENT_TYPE' => 'application/json', 'rack.input' => body, lint: true)

expect(response.status).to eq(200)
expect(response.body).to eq(%({:id=>"23"}))
end

it 'is successful (JSON as array)' do
body = StringIO.new( %(["alpha", "beta"]).encode(Encoding::ASCII_8BIT) )
body = StringIO.new(%(["alpha", "beta"]).encode(Encoding::ASCII_8BIT))
response = @app.patch('/books/23', 'CONTENT_TYPE' => 'application/json', 'rack.input' => body, lint: true)

expect(response.status).to eq(200)
Expand All @@ -39,7 +39,7 @@

# See https://github.com/hanami/utils/issues/169
it 'does not eval untrusted input' do
body = StringIO.new( %({"json_class": "Foo"}).encode(Encoding::ASCII_8BIT) )
body = StringIO.new(%({"json_class": "Foo"}).encode(Encoding::ASCII_8BIT))
response = @app.patch('/books/23', 'CONTENT_TYPE' => 'application/json', 'rack.input' => body, lint: true)

expect(response.status).to eq(200)
Expand All @@ -48,7 +48,7 @@

it 'is idempotent' do
2.times do
body = StringIO.new( %({"published":"true"}).encode(Encoding::ASCII_8BIT) )
body = StringIO.new(%({"published":"true"}).encode(Encoding::ASCII_8BIT))
response = @app.patch('/books/23', 'CONTENT_TYPE' => 'application/json', 'rack.input' => body, lint: true)

expect(response.status).to eq(200)
Expand All @@ -57,15 +57,15 @@
end

it 'is successful (XML)' do
body = StringIO.new( %(<name>LG</name>).encode(Encoding::ASCII_8BIT) )
body = StringIO.new(%(<name>LG</name>).encode(Encoding::ASCII_8BIT))
response = @app.patch('/authors/23', 'CONTENT_TYPE' => 'application/xml', 'rack.input' => body, lint: true)

expect(response.status).to eq(200)
expect(response.body).to eq(%({:name=>"LG", :id=>"23"}))
end

it 'is successful (XML aliased mime)' do
body = StringIO.new( %(<name>MGF</name>).encode(Encoding::ASCII_8BIT) )
body = StringIO.new(%(<name>MGF</name>).encode(Encoding::ASCII_8BIT))
response = @app.patch('/authors/15', 'CONTENT_TYPE' => 'text/xml', 'rack.input' => body, lint: true)

expect(response.status).to eq(200)
Expand Down
File renamed without changes.
Expand Up @@ -16,11 +16,11 @@

it 'recognizes single endpoint (with naming convention)' do
response = @app.get('/ccs', lint: true)
expect(response.body).to eq('Hello from CreditCards::Index')
expect(response.body).to eq('Hello from CreditCards::Index')
end

it 'recognizes RESTful endpoint' do
response = @app.get('/credit_cards', lint: true)
expect(response.body).to eq('Hello from CreditCards::Index')
expect(response.body).to eq('Hello from CreditCards::Index')
end
end
Expand Up @@ -2,16 +2,16 @@
# Bug https://github.com/hanami/router/issues/73
it 'respects the Rack spec' do
router = Hanami::Router.new(force_ssl: true)
router.public_send(:get, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(:get, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })
app = Rack::MockRequest.new(router)

app.get('/http_destination', lint: true)
end

%w{get}.each do |verb|
%w[get].each do |verb|
it "force_ssl to true and scheme is http, return 307 and new location, verb: #{verb}" do
router = Hanami::Router.new(force_ssl: true)
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(verb, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })
app = Rack::MockRequest.new(router)

status, headers, body = app.public_send(verb, '/http_destination', lint: true)
Expand All @@ -23,7 +23,7 @@

it "force_ssl to true and scheme is https, return 200, verb: #{verb}" do
router = Hanami::Router.new(force_ssl: true, scheme: 'https', host: 'hanami.test')
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(verb, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })
app = Rack::MockRequest.new(router)

status, headers, body = app.public_send(verb, 'https://hanami.test/http_destination', lint: true)
Expand All @@ -34,10 +34,10 @@
end
end

%w{post put patch delete options}.each do |verb|
%w[post put patch delete options].each do |verb|
it "force_ssl to true and scheme is http, return 307 and new location, verb: #{verb}" do
router = Hanami::Router.new(force_ssl: true)
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(verb, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })
app = Rack::MockRequest.new(router)

status, headers, body = app.public_send(verb, '/http_destination', lint: true)
Expand All @@ -49,7 +49,7 @@

it "force_ssl to true and added query string, verb: #{verb}" do
router = Hanami::Router.new(force_ssl: true)
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(verb, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })

app = Rack::MockRequest.new(router)

Expand All @@ -62,7 +62,7 @@

it "force_ssl to true and added port, verb: #{verb}" do
router = Hanami::Router.new(force_ssl: true, port: 4000)
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(verb, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })

app = Rack::MockRequest.new(router)

Expand All @@ -75,7 +75,7 @@

it "force_ssl to true, added host and port, verb: #{verb}" do
router = Hanami::Router.new(force_ssl: true, host: 'hanamirb.org', port: 4000)
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(verb, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })

app = Rack::MockRequest.new(router)

Expand All @@ -88,7 +88,7 @@

it "force_ssl to false and scheme is http, return 200 and doesn't return new location, verb: #{verb}" do
router = Hanami::Router.new(force_ssl: false)
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(verb, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })

app = Rack::MockRequest.new(router)

Expand All @@ -101,7 +101,7 @@

it "force_ssl to false and scheme is https, return 200 and doesn't return new location, verb: #{verb}" do
router = Hanami::Router.new(force_ssl: false, scheme: 'https')
router.public_send(verb, '/http_destination', to: ->(env) { [200, {}, ['http destination!']] })
router.public_send(verb, '/http_destination', to: ->(_env) { [200, {}, ['http destination!']] })

app = Rack::MockRequest.new(router)

Expand Down

0 comments on commit 51017aa

Please sign in to comment.