我最近将测试从使用Cucumber / Capybara转换为Rspec / Capybara。我正在使用ActiveAdmin。当我使用Cucumber对ActiveAdmin运行测试时,测试运行,一切都通过了。使用Rspec运行测试时,我收到:
Rendered /home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/app/views/active_admin/resource/index.html.arb (210.6ms)
Completed 500 Internal Server Error in 244ms
ActionView::Template::Error (undefined method `action_methods' for nil:NilClass):
1: insert_tag renderer_for(:index)
authlogic (3.4.2) lib/authlogic/controller_adapters/abstract_adapter.rb:63:in `method_missing'
/home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/lib/active_admin/resource/action_items.rb:55:in `block in add_default_action_items'
/home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/lib/active_admin/views/action_items.rb:9:in `instance_exec'
/home/vagrant/.rvm/gems/ruby-2.0.0-p451/bundler/gems/active_admin-d11c0a56504a/lib/active_admin/views/action_items.rb:9:in `block (2 levels) in build'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:31:in `block in build_tag'
arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `with_current_arbre_element'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
arbre (1.0.1) lib/arbre/element/builder_methods.rb:14:in `span'
那只是回溯的十行。实际上更大。让我知道是否应该粘贴。
导致此错误的rspec有何不同?
我正在使用rspec(2.14.1),activeadmin(master),ruby(2.0),rails(4.1.1)。
谢谢。
更新
这是我的activeadmin资源:
ActiveAdmin.register UserPermission, :as => 'Support User' do
config.batch_actions = false
config.clear_action_items!
config.filters = false
actions :new, :create, :index, :destroy
action_item only: [:index] do
link_to 'Add Support User', new_admin_support_user_path
end
controller do
def scoped_collection
UserPermission.where(permission: 'support')
end
def destroy
begin
permission = UserPermission.find_by_id_and_permission!(
params[:id], UserPermission::SUPPORT)
permission.destroy if permission.present?
redirect_to admin_support_users_path, notice: 'Support user removed.'
rescue ActiveRecord::RecordNotFound
redirect_to admin_support_users_path, alert: 'Support user not found.'
end
end
def create
user = User.find_by_email(params[:email])
if user
UserPermission.create(:user_id => user.id,
:permission => UserPermission::SUPPORT,
:creator => current_user)
redirect_to admin_support_users_path, notice: 'Support user added.'
else
redirect_to new_admin_support_user_path, alert: 'User not found'
end
end
end
form partial: "form"
index :download_links => false do
column :email do |permission|
permission.user.email
end
column :created_by do |permission|
if permission.created_by.present?
u = User.find_by_id(permission.created_by)
u.email
end
end
column :created_at
actions
end
menu :parent => 'Users', :priority => 1
end
我终于能够重新解决这个问题。准确指出错误在说些什么有点困难,但是该错误是由于多种原因造成的。
我的解决方法是根本不尝试呈现那些丢失的动作。除了动作,我现在有:
actions defaults: false do |permission|
link_to 'Delete', admin_support_user_path(permission), :method => :delete
end
这有效。但是,我仍然不明白为什么只有rspec对此有问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句