2016-06-08 100 views
0

我试图找出如何测试得到(MINITEST),有语言环境,是一个范围内的路线:如何测试(MINITEST)与Rails的区域

scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do 
    get 'static_pages/about' 
    resources :salas  
    end 

这不起作用:

require 'test_helper' 

class StaticPagesControllerTest < ActionController::TestCase 
    test "should get about" do 
    get :about 
    assert_response :success 
    end 

end 

和将产生以下输出:

# Running: 

E 

Finished in 0.301302s, 3.3189 runs/s, 0.0000 assertions/s. 

    1) Error: 
StaticPagesControllerTest#test_should_get_about: 
ActionController::UrlGenerationError: No route matches {:action=>"about", :controller=>"static_pages"} 
    test/controllers/static_pages_controller_test.rb:5:in `block in <class:StaticPagesControllerTest>' 

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips 

耙路线:

 Prefix Verb URI Pattern      

    Controller#Action 
static_pages_about GET /:locale/static_pages/about(.:format) static_pages#about {:locale=>/en|es/} 
      salas GET /:locale/salas(.:format)    salas#index {:locale=>/en|es/} 
        POST /:locale/salas(.:format)    salas#create {:locale=>/en|es/} 
      new_sala GET /:locale/salas/new(.:format)   salas#new {:locale=>/en|es/} 
     edit_sala GET /:locale/salas/:id/edit(.:format)  salas#edit {:locale=>/en|es/} 
       sala GET /:locale/salas/:id(.:format)   salas#show {:locale=>/en|es/} 
        PATCH /:locale/salas/:id(.:format)   salas#update {:locale=>/en|es/} 
        PUT /:locale/salas/:id(.:format)   salas#update {:locale=>/en|es/} 
        DELETE /:locale/salas/:id(.:format)   salas#destroy {:locale=>/en|es/} 
        GET /*path(.:format)      redirect(301, /en/%{path}) 
       root GET /         salas#index 

我想也许我需要通过语言环境测试,但我不确定如何。 谢谢!

回答

0

在这个标题下面:Function Tests for your Controllers在Rails指南:测试Rails指南中显示了get方法的约定。要将params传递给该方法,请将其作为调用的第二个参数。

get :about, locale: 'en' 
+0

非常感谢,它的工作!我会检查指南。谢谢 ! – user6442102

相关问题