spec/controller_spec.rb in rasti-web-2.0.1 vs spec/controller_spec.rb in rasti-web-2.1.0
- old
+ new
@@ -1,9 +1,9 @@
require 'minitest_helper'
class TestController < Rasti::Web::Controller
-
+
CustomError = Class.new StandardError
def self.hooks_log
@hooks_log ||= []
end
@@ -14,18 +14,18 @@
after_action do |action_name|
self.class.hooks_log << "After all: #{action_name}"
end
- before_action :test do
+ before_action :test do
self.class.hooks_log << 'Before single: test'
end
- after_action :test do
+ after_action :test do
self.class.hooks_log << 'After single: test'
end
-
+
def test
render.html 'Test HTML'
end
def exception
@@ -53,21 +53,21 @@
describe Rasti::Web::Controller do
before do
TestController.hooks_log.clear
end
-
+
it 'Action endpoint' do
action = TestController.action :test
env = Rack::MockRequest.env_for '/test'
status, headers, response = action.call env
action.must_be_instance_of Rasti::Web::Endpoint
status.must_equal 200
headers['Content-Type'].must_equal 'text/html; charset=utf-8'
response.body.must_equal ['Test HTML']
-
+
TestController.hooks_log.must_equal [
'Before single: test',
'After single: test'
]
end
@@ -82,10 +82,11 @@
action = TestController.action :explicit_fail
env = Rack::MockRequest.env_for '/explicit_fail'
status, headers, response = action.call env
status.must_equal 500
+ headers['Content-Type'].must_be_nil
response.body.must_equal ['Explicit error']
TestController.hooks_log.must_equal [
'Before all: explicit_fail',
'After all: explicit_fail'
@@ -96,10 +97,11 @@
action = TestController.action :implicit_fail
env = Rack::MockRequest.env_for '/implicit_fail'
status, headers, response = action.call env
status.must_equal 500
+ headers['Content-Type'].must_be_nil
response.body.must_equal ['Implicit error']
TestController.hooks_log.must_equal [
'Before all: implicit_fail',
'After all: implicit_fail'
@@ -107,10 +109,10 @@
end
it 'Unexpected exception' do
action = TestController.action :exception
env = Rack::MockRequest.env_for '/exception'
-
+
error = proc { action.call env }.must_raise RuntimeError
error.message.must_equal 'Unexpected error'
TestController.hooks_log.must_equal [
'Before all: exception',
\ No newline at end of file