3

我正在创建一个使用 jstree 的 rails 应用程序。现在我正在尝试在 rspec 测试中测试 jstree 的功能,使用 capybara 和 selenium 驱动程序(js:true)。测试是:

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'

事情是这样的,/surveyors/themes/default/style.css首先不应该是一条路线。它正在寻找的资产位于assets/themes/default/style.css. 这是一个特定于 js-tree 的样式表。在测试中插入一些调试器语句,我可以验证页面确实有选择器。如果页面确实有选择器,我只会得到异常......也就是说,如果我将内容更改为have_selectorto "BadSelector",测试将定期失败(没有找到选择器)。js-tree 功能在手动查看时有效。

在此先感谢您的帮助

Rails 3.2.8 Rspec 2.12 Capybara 2.0

4

1 回答 1

3

Echo,有人在吗?不,看来我是在给自己写信。

如果其他人遇到这个问题,我确实想出了如何解决它,尽管我不能 100% 确定根本原因。当我“安装”jstree 时,我只是将它转储到资产管道(javascript)中。在开发中效果很好,但在测试中效果不佳(见上文)。Jstree 使用它的主题插件来加载样式表,而不是将它们直接放在样式表文件夹中。在测试中,无论出于何种原因,它生成的路径都会作为当前页面路径的前缀。我使用 jstree rails gem 解决了这个问题,它明确引用了用于样式表的目录。问题解决了。

于 2012-12-27T22:39:51.620 回答