Tag: 应该

Rails在function测试中找不到路由

Rails版本3.0.4和Ruby 1.9.2 我正在使用设计gem,并设置我的应用程序,以便用户必须登录才能执行任何操作。 在编写我的function测试时,我发现所有的测试都抛出了同样的错误。 `method_missing’: undefined method `new_user_session_path’ 这很奇怪,如果我rake routes我可以看到 new_user_session GET /devise/login(.:format) {:action=>”new”, :controller=>”devise/sessions”} 我还可以确认,当我运行应用程序时,所有link_to可以使用该路径。 对于某个控制器的测试来看其他路线,我有什么特别之处吗? 的routes.rb Nge::Application.routes.draw do resources :companies resources :users devise_for :users, :path => “devise”, :path_names => { :sign_in => ‘login’, :sign_out => ‘logout’, :password => ‘secret’, :confirmation => ‘verification’, :unlock => ‘unblock’, :registration => ‘register’, :sign_up => ‘cmon_let_me_in’ } … […]

应该:测试validates_presence_of:on =>:update

我在我工作的一个项目中使用了Shoulda和Test :: Unit。 我遇到的问题是我最近改变了这个: class MyModel < ActiveRecord::Base validates_presence_of :attribute_one, :attribute_two end 对此: class MyModel :update end 以前,我的(传递)测试看起来像这样: class MyModelTest < ActiveSupport::TestCase should_validate_presence_of :attribute_one, :attribute_two end 据我所知, should_validate_presence_of没有参数会导致此测试继续传递上面指定的更改。 在测试需求:attribute_two ,没有放弃Shoulda,有什么方法可以解决这个问题吗?

rails attr_accessible rspec check

当我想测试RSpec是否无法访问属性时我就是这样做的 class Foo attr_accesible :something_else end describe Foo do it(‘author should not be accessible’) {lambda{described_class.new(:author=>true)}.should raise_error ActiveModel::MassAssignmentSecurity::Error} it(‘something_else should be accessible’){lambda{described_class.new(:something_else=>true)}.should_not raise_error ActiveModel::MassAssignmentSecurity::Error} end 这样做有更好的方法吗? …谢谢

用shoulda测试设计

我在使用shoulda测试设计方面遇到了一些困难: 2) Error: test: handle :index logged as admin should redirect to Daily page. (Admin::DailyClosesControllerTest): NoMethodError: undefined method `env’ for nil:NilClass devise (1.0.6) [v] lib/devise/test_helpers.rb:52:in `setup_controller_for_warden’ 我在test_helper中有这个: include Devise::TestHelpers 想法? 提前致谢, 克里斯提

One-liner应该使用大括号语法

在Rails Test Prescriptions(b10.0,第176页)一书中,有一些单行断言的例子,如下所示: should “be successful” { assert_response :success } 这对我来说似乎不是有效的ruby语法,并且ruby报告左大括号是意外的。 为了解析它,我必须将其更改为 should “be successful”; do assert_response :success end 第一个例子的语法有什么问题?

如何在Rails测试中指定POST参数?

使用Test :: Unit和Shoulda。 试图测试Users.create 。 我的理解是Rails表单为这样的对象发送params: user[email] 在你的行动中变成哈希,对吧? params[:user][:email] 好的,所以在我的测试中我试过…… setup { post :create, :post => { ‘user[email]’ => ‘invalid@abc’ } } 和 setup { post :create, :post => { :user => { :email => ‘abc@abcd’ } } } 在这两种情况下,在我的行动中, params[:user]为零。