I’m creating a rails application that makes use of jstree. Right now I’m trying to test the functionality of the jstree in an rspec test, using capybara with the selenium driver (js: true). The test is:
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
This is in a shared_example, and obj is an object related to the test (in this case, a surveyor). My js tree should produce nodes with id like “_”. So I’m expecting something like “Surveyor_1”.
When run, I get the following error:
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'
Here’s the thing though, /surveyors/themes/default/style.css shouldn’t be a route in the first place. The asset that it’s looking for is in assets/themes/default/style.css. This is a js-tree specific style sheet. Plugging in some debugger statements in the test, I can verify that page does have the selector. I only get the exception if the page does have the selector… that is, if I change the contents of have_selector to "BadSelector", the test will fail regularly (did not find selector). The js-tree functionality works when manually viewed.
Thanks in advance for your help
Rails 3.2.8 Rspec 2.12 Capybara 2.0
Echo, is anyone in here? Nope, looks like I’m writing to myself.
If someone else runs into this problem, I did figure out how to fix it, though I’m not 100 percent sure of the root cause. When I “installed” jstree I simply dumped it into the assets pipeline (javascript). Which worked fine in development, but not in testing (see above). Jstree uses its themes plugin to load style sheets rather than having them located directly in stylesheets folder. In testing, for whatever reason, the path that it generates prefixes the path of the current page. I got around this using the jstree rails gem, which explicitly references the directory to use for stylesheets. Problem solved.