From 1e1d52cc4729fa6acb81de07cb20dc4c7e07de89 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 2 Apr 2015 14:35:39 +1100 Subject: [PATCH] Adding 'selected' option to have_select2 matcher --- spec/support/matchers/select2_matchers.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/support/matchers/select2_matchers.rb b/spec/support/matchers/select2_matchers.rb index 8b7bc2f834..67cfcd81d0 100644 --- a/spec/support/matchers/select2_matchers.rb +++ b/spec/support/matchers/select2_matchers.rb @@ -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