##Table of Contents
The eventually
method re-runs the passed block until it either evaluates true or times out. Its timeout defaults to the Capybara.default_max_wait_time
, but can also be specified as an argument in seconds.
eventually { async_action == true } # loops for up to Capybara.default_max_wait_time
eventually(10) { async_action == true } # loops for up to 10 seconds
You can easily check for widgets in your RSpec steps by using the custom see
matcher.
For a widget defined in the User role:
class User < Capybara::UI::Role
widget :todo_item, -> (text) { ['.todo-item', text: text] }
end
The role can expect to see
, or not_to see
, that widget.
expect(User.new).to see :todo_item, 'Buy Milk'
You can see
more complex logic by writing a method that begins with see_
and ends with ?
:
class User < Capybara::UI::Role
widget :todo_item, -> (text) { ['.todo-item', text: text] }
def see_custom_logic?(text)
visible?(:todo_item, text) &&
(1 + 1) == 2
end
end
expect(User.new).to see :custom_logic, 'my text'
widget#diff
checks the table version of a widget against a cucumber table.
Then(/^some step that takes in a cucumber table$/) do |table|
# when the cucumber table values do not match the widget's values
widget(:my_widget).diff(table) # raises error Cucumber::MultilineArgument::DataTable::Different
# when the cucumber table values match the widget's values
widget(:my_widget).diff(table) # => true
end
Pass ignore_case: true
, for a case-insensitive table match.
Then(/^some step that takes in a cucumber table$/) do |table|
widget(:my_widget).diff(table, ignore_case: true)
end