Make ember route expectations smarter

This commit is contained in:
2014-10-17 18:23:48 +02:00
parent 84b1060c6f
commit 8837037b05
6 changed files with 19 additions and 7 deletions
+16 -3
View File
@@ -15,13 +15,26 @@ module SpecRouteHelpers
end
def ember_route_should_be(route_def)
ember_route.should == route_def
max_wait = 4
time = 0.0
time_step = 0.25
while time < max_wait && ember_route != route_def
time += time_step
sleep time_step
end
ember_route(omit_should_raise: true).should == route_def
end
def ember_route
def ember_route(omit_should_raise: nil)
# currentRouteName does not include model information: /list/123 => currentRouteName == 'list'
# page.evaluate_script %|App.__container__.lookup('controller:application').get('currentRouteName')|
# page.evaluate_script %|App.__container__.lookup('router:main').location.lastSetURL| # not working for direct path supplier#/settings
page.evaluate_script %{App.__container__ && (window.location.hash || "#/").substr(1)}
route = page.evaluate_script %{App.__container__ && (window.location.hash || "#/").substr(1)}
unless omit_should_raise
def route.should(*)
raise "Cannot call should on ember route. Use ember_route_should_be instead"
end
end
route
end
end