Adding 'selected' option to have_select2 matcher

This commit is contained in:
Rob Harrington
2015-04-02 14:35:39 +11:00
parent 76648b97b0
commit 1e1d52cc47

View File

@@ -14,6 +14,10 @@ RSpec::Matchers.define :have_select2 do |id, options={}|
results << node.has_selector?(from)
if results.all?
results << selected_option_is(from, options[:selected]) if options.key? :selected
end
if results.all?
results << all_options_present(from, options[:with_options]) if options.key? :with_options
results << exact_options_present(from, options[:options]) if options.key? :options
@@ -47,6 +51,12 @@ RSpec::Matchers.define :have_select2 do |id, options={}|
end
end
def selected_option_is(from, text)
within find(from) do
find("a.select2-choice").text == text
end
end
def with_select2_open(from)
find(from).click
r = yield