Ruby on rails 使用RSpec2和Rails3.0.4,如何从XML测试像admin_controller.rb这样的通用控制器 有什么问题吗
我想测试一个before过滤器,如果失败,它会在XML和JSON中呈现错误。 当从经典控制器测试时,它工作良好,当从 如果应用程序控制器发生故障,它将直接启动应用程序控制器 代码的轻版本 规格/控制器/管理控制器\u规格rbRuby on rails 使用RSpec2和Rails3.0.4,如何从XML测试像admin_controller.rb这样的通用控制器 有什么问题吗,ruby-on-rails,rspec2,Ruby On Rails,Rspec2,我想测试一个before过滤器,如果失败,它会在XML和JSON中呈现错误。 当从经典控制器测试时,它工作良好,当从 如果应用程序控制器发生故障,它将直接启动应用程序控制器 代码的轻版本 规格/控制器/管理控制器\u规格rb require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminController do controller(AdminController) do de
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AdminController do
controller(AdminController) do
def index
render :text => 'ok'
end
end
it "should include errors properly formated" do
get :index, :format => 'xml'
response.body.should == "block"
end
end
class AdminController < ApplicationController
before_filter :block_something
protected
def block_something
respond_to do |wants|
wants.xml {
render :text => 'block'
}
end
end
end
app/controller/admin\u controller.rb
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe AdminController do
controller(AdminController) do
def index
render :text => 'ok'
end
end
it "should include errors properly formated" do
get :index, :format => 'xml'
response.body.should == "block"
end
end
class AdminController < ApplicationController
before_filter :block_something
protected
def block_something
respond_to do |wants|
wants.xml {
render :text => 'block'
}
end
end
end
更新,带回溯:感谢Ryan Bigg的推荐
它给出了与上述示例不同的控制器和过滤器名称。该应用程序使用admin_controller.rb和block_挂起过滤器
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/template/resolver.rb:61:in `<<'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/template/resolver.rb:61:in `build_path'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/template/resolver.rb:54:in `find_templates'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/template/resolver.rb:20:in `find_all'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/template/resolver.rb:39:in `cached'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/template/resolver.rb:19:in `find_all'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/paths.rb:21:in `find_all'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/paths.rb:20:in `each'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/paths.rb:20:in `find_all'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/paths.rb:21:in `find_all'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/paths.rb:20:in `each'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/paths.rb:20:in `find_all'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/paths.rb:28:in `exists?'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_view/lookup_context.rb:90:in `template_exists?'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/view_paths.rb:11:in `__send__'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/view_paths.rb:11:in `template_exists?'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/layouts.rb:272:in `_layout'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/layouts.rb:345:in `_default_layout'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/layouts.rb:323:in `_layout_for_option'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/layouts.rb:290:in `_normalize_options'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/rendering.rb:41:in `_normalize_options'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/compatibility.rb:50:in `_normalize_options'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/rendering.rb:101:in `render_to_string'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/rendering.rb:93:in `render'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/rendering.rb:17:in `render'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:40:in `render_without_wicked_pdf'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/core_ext/benchmark.rb:5:in `ms'
# /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/core_ext/benchmark.rb:5:in `ms'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:40:in `render_without_wicked_pdf'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
# /Library/Ruby/Gems/1.8/gems/activerecord-3.0.4/lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:39:in `render_without_wicked_pdf'
# ./app/controllers/admin_controller.rb:36:in `block_suspended'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/mime_responds.rb:192:in `call'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/mime_responds.rb:192:in `respond_to'
# ./app/controllers/admin_controller.rb:33:in `block_suspended'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:466:in `_run__1727617933__process_action__199225275__callbacks'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:409:in `send'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:93:in `send'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/callbacks.rb:93:in `run_callbacks'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/callbacks.rb:17:in `process_action'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/notifications.rb:52:in `instrument'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
# /Library/Ruby/Gems/1.8/gems/activesupport-3.0.4/lib/active_support/notifications.rb:52:in `instrument'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/rescue.rb:17:in `process_action'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/base.rb:119:in `process'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/abstract_controller/rendering.rb:41:in `process'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/metal/testing.rb:12:in `process_with_new_base_test'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/test_case.rb:412:in `process'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/test_case.rb:47:in `process'
# /Library/Ruby/Gems/1.8/gems/actionpack-3.0.4/lib/action_controller/test_case.rb:350:in `get'
# ./spec/controllers/admin_controller_spec.rb:272
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:29:in `instance_eval'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:29:in `run_in'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `run_all'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `each'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:64:in `run_all'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/hooks.rb:110:in `run_hook'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `each'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:191:in `eval_before_eachs'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:144:in `run_before_each'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:48:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:106:in `with_around_hooks'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:46:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:99:in `with_pending_capture'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98:in `catch'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98:in `with_pending_capture'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:45:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:262:in `run_examples'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:258:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:258:in `run_examples'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:232:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `map'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:27:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/reporter.rb:12:in `report'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:24:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
# /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `autorun'
# /usr/bin/rspec:19
#/Library/Ruby/Gems/1.8/Gems/actionpack-3.0.4/lib/action\u view/template/resolver.rb:61:在`中,我现在已经升级到Ruby 1.9.2,所有规范都通过了,无需任何更改
看起来Ruby 1.8.7有一个限制,需要额外的解决方法。您能在命令末尾使用-b
开关运行测试吗,这样我们就可以看到错误的回溯?我刚刚开始遇到这个完全相同的问题。我相信我早就有了这个规范。如果你发现如何解决它,请随时通知我们;-)