2012-12-18 69 views
3

我正在創建一個使用jstree的rails應用程序。現在我試圖在一個rspec測試中使用capybara和selenium驅動(js:true)來測試jstree的功能。該測試是:尋找不應存在的資產路線時Rspec /水豚/硒測試失敗

scenario "the object associated with the data-pane is selected in the tree", js: true do 
    visit surveyor_path 
    using_wait_time(20) { expect(page).to have_selector("##{obj.class.name}_#{obj.id.to_s}") } 
end 

這在shared_example,和obj爲與測試對象(在這種情況下,測量員)。我的JS樹應該產生像「_」一樣的ID的節點。所以我期待像「Surveyor_1」這樣的東西。

運行時,我收到以下錯誤:

Failure/Error: Unable to find matching line from backtrace 
    ActionController::RoutingError: 
     No route matches [GET] "/surveyors/themes/default/style.css" 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/rack/logger.rb:26:in `call_app' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/rack/logger.rb:16:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/request_id.rb:22:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/static.rb:62:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/engine.rb:479:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application.rb:223:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:134:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/urlmap.rb:64:in `block in call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in `each' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/urlmap.rb:49:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/capybara-2.0.1/lib/capybara/server.rb:19:in `call' 
    # /Users/chrisgat/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service' 
    # /Users/chrisgat/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 
    # /Users/chrisgat/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 
    # /Users/chrisgat/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 

這裏的東西雖然​​不應該擺在首位的路線。它正在尋找的資產是assets/themes/default/style.css。這是一個js-tree特定的樣式表。在測試中插入一些調試器語句,我可以驗證頁面是否有選擇器。如果頁面確實有選擇器,我只會得到異常......也就是說,如果我將have_selector的內容更改爲"BadSelector",則測試將定期失敗(未找到選擇器)。手動查看時,js-tree功能起作用。

在此先感謝您的幫助

的Rails 3.2.8 Rspec的2.12水豚2.0

回答

3

回聲,是誰在這裏?不,看起來像我在給自己寫信。

如果別人遇到這個問題,我確實弄清楚瞭如何解決這個問題,儘管我並不是100%確定問題的根源。當我「安裝」jstree時,我簡單地將它轉儲到資產管道(javascript)中。在開發中哪些工作正常,但沒有在測試中(見上文)。 Jstree使用它的主題插件來加載樣式表,而不是直接將它們放置在樣式表文件夾中。在測試中,無論出於何種原因,它所生成的路徑都會爲當前頁面的路徑添加前綴。我使用jstree rails gem解決了這個問題,它明確引用了用於樣式表的目錄。問題解決了。

+0

請注意,我安裝了jstree-rails gem的tristanm分支,該分支被記錄爲稍微好一點,並且可以使用更多jstree插件。 – cgat