Best Capybara code snippet using Capybara.Minitest.Assertions.determine_subject
minitest.rb
Source:minitest.rb
...7 ## Assert text exists8 # see {Capybara::Node::Matchers#assert_text}9 def assert_text(*args)10 self.assertions += 111 subject, *args = determine_subject(args)12 subject.assert_text(*args)13 rescue Capybara::ExpectationNotMet => e14 raise ::Minitest::Assertion, e.message15 end16 alias_method :assert_content, :assert_text17 ## Assert text does not exist18 # see {Capybara::Node::Matchers#assert_no_text}19 def assert_no_text(*args)20 self.assertions += 121 subject, *args = determine_subject(args)22 subject.assert_no_text(*args)23 rescue Capybara::ExpectationNotMet => e24 raise ::Minitest::Assertion, e.message25 end26 alias_method :refute_text, :assert_no_text27 alias_method :refute_content, :refute_text28 alias_method :assert_no_content, :refute_text29 ## Assert selector exists on page30 # see {Capybara::Node::Matchers#assert_selector}31 def assert_selector(*args, &optional_filter_block)32 self.assertions +=133 subject, *args = determine_subject(args)34 subject.assert_selector(*args, &optional_filter_block)35 rescue Capybara::ExpectationNotMet => e36 raise ::Minitest::Assertion, e.message37 end38 ## Assert selector does not exist on page39 # see {Capybara::Node::Matchers#assert_no_selector}40 def assert_no_selector(*args, &optional_filter_block)41 self.assertions +=142 subject, *args = determine_subject(args)43 subject.assert_no_selector(*args, &optional_filter_block)44 rescue Capybara::ExpectationNotMet => e45 raise ::Minitest::Assertion, e.message46 end47 alias_method :refute_selector, :assert_no_selector48 ## Assert element matches selector49 # see {Capybara::Node::Matchers#assert_matches_selector}50 def assert_matches_selector(*args, &optional_filter_block)51 self.assertions += 152 subject, *args = determine_subject(args)53 subject.assert_matches_selector(*args, &optional_filter_block)54 rescue Capybara::ExpectationNotMet => e55 raise ::Minitest::Assertion, e.message56 end57 ## Assert element does not match selector58 # see {Capybara::Node::Matchers#assert_not_matches_selector}59 def assert_not_matches_selector(*args, &optional_filter_block)60 self.assertions += 161 subject, *args = determine_subject(args)62 subject.assert_not_matches_selector(*args, &optional_filter_block)63 rescue Capybara::ExpectationNotMet => e64 raise ::Minitest::Assertion, e.message65 end66 alias_method :refute_matches_selector, :assert_not_matches_selector67 %w(title current_path).each do |selector_type|68 define_method "assert_#{selector_type}" do |*args|69 begin70 self.assertions += 171 subject, *args = determine_subject(args)72 subject.public_send("assert_#{selector_type}",*args)73 rescue Capybara::ExpectationNotMet => e74 raise ::Minitest::Assertion, e.message75 end76 end77 define_method "assert_no_#{selector_type}" do |*args|78 begin79 self.assertions += 180 subject, *args = determine_subject(args)81 subject.public_send("assert_no_#{selector_type}",*args)82 rescue Capybara::ExpectationNotMet => e83 raise ::Minitest::Assertion, e.message84 end85 end86 alias_method "refute_#{selector_type}", "assert_no_#{selector_type}"87 end88 %w(xpath css link button field select table).each do |selector_type|89 define_method "assert_#{selector_type}" do |*args, &optional_filter_block|90 subject, *args = determine_subject(args)91 locator, options = *args, {}92 locator, options = nil, locator if locator.is_a? Hash93 assert_selector(subject, selector_type.to_sym, locator, options, &optional_filter_block)94 end95 define_method "assert_no_#{selector_type}" do |*args, &optional_filter_block|96 subject, *args = determine_subject(args)97 locator, options = *args, {}98 locator, options = nil, locator if locator.is_a? Hash99 assert_no_selector(subject, selector_type.to_sym, locator, options, &optional_filter_block)100 end101 alias_method "refute_#{selector_type}", "assert_no_#{selector_type}"102 end103 %w(xpath css).each do |selector_type|104 define_method "assert_matches_#{selector_type}" do |*args, &optional_filter_block|105 subject, *args = determine_subject(args)106 assert_matches_selector(subject, selector_type.to_sym, *args, &optional_filter_block)107 end108 define_method "assert_not_matches_#{selector_type}" do |*args, &optional_filter_block|109 subject, *args = determine_subject(args)110 assert_not_matches_selector(subject, selector_type.to_sym, *args, &optional_filter_block)111 end112 alias_method "refute_matches_#{selector_type}", "assert_not_matches_#{selector_type}"113 end114 %w(checked unchecked).each do |field_type|115 define_method "assert_#{field_type}_field" do |*args, &optional_filter_block|116 subject, *args = determine_subject(args)117 locator, options = *args, {}118 locator, options = nil, locator if locator.is_a? Hash119 assert_selector(subject, :field, locator, options.merge(field_type.to_sym => true), &optional_filter_block)120 end121 define_method "assert_no_#{field_type}_field" do |*args, &optional_filter_block|122 subject, *args = determine_subject(args)123 locator, options = *args, {}124 locator, options = nil, locator if locator.is_a? Hash125 assert_no_selector(subject, :field, locator, options.merge(field_type.to_sym => true), &optional_filter_block)126 end127 alias_method "refute_#{field_type}_field", "assert_no_#{field_type}_field"128 end129 ##130 # Assertion that there is xpath131 #132 # @!method assert_xpath133 # see Capybara::Node::Matchers#has_xpath?134 ##135 # Assertion that there is no xpath136 #137 # @!method refute_xpath138 # @!method assert_no_xpath139 # see Capybara::Node::Matchers#has_no_xpath?140 ##141 # Assertion that there is css142 #143 # @!method assert_css144 # see Capybara::Node::Matchers#has_css?145 ##146 # Assertion that there is no css147 #148 # @!method refute_css149 # @!method assert_no_css150 # see Capybara::Node::Matchers#has_no_css?151 ##152 # Assertion that there is link153 #154 # @!method assert_link155 # see {Capybara::Node::Matchers#has_link?}156 ##157 # Assertion that there is no link158 #159 # @!method assert_no_link160 # @!method refute_link161 # see {Capybara::Node::Matchers#has_no_link?}162 ##163 # Assertion that there is button164 #165 # @!method assert_button166 # see {Capybara::Node::Matchers#has_button?}167 ##168 # Assertion that there is no button169 #170 # @!method refute_button171 # @!method assert_no_button172 # see {Capybara::Node::Matchers#has_no_button?}173 ##174 # Assertion that there is field175 #176 # @!method assert_field177 # see {Capybara::Node::Matchers#has_field?}178 ##179 # Assertion that there is no field180 #181 # @!method refute_field182 # @!method assert_no_field183 # see {Capybara::Node::Matchers#has_no_field?}184 ##185 # Assertion that there is checked_field186 #187 # @!method assert_checked_field188 # see {Capybara::Node::Matchers#has_checked_field?}189 ##190 # Assertion that there is no checked_field191 #192 # @!method assert_no_checked_field193 # @!method refute_chceked_field194 ##195 # Assertion that there is unchecked_field196 #197 # @!method assert_unchecked_field198 # see {Capybara::Node::Matchers#has_unchecked_field?}199 ##200 # Assertion that there is no unchecked_field201 #202 # @!method assert_no_unchecked_field203 # @!method refute_unchceked_field204 ##205 # Assertion that there is select206 #207 # @!method assert_select208 # see {Capybara::Node::Matchers#has_select?}209 ##210 # Assertion that there is no select211 #212 # @!method refute_select213 # @!method assert_no_select214 # see {Capybara::Node::Matchers#has_no_select?}215 ##216 # Assertion that there is table217 #218 # @!method assert_table219 # see {Capybara::Node::Matchers#has_table?}220 ##221 # Assertion that there is no table222 #223 # @!method refute_table224 # @!method assert_no_table225 # see {Capybara::Node::Matchers#has_no_table?}226 ##227 # Assertion that page title does match228 #229 # @!method assert_title230 # see {Capybara::Node::DocumentMatchers#assert_title}231 ##232 # Assertion that page title does not match233 #234 # @!method refute_title235 # @!method assert_no_title236 # see {Capybara::Node::DocumentMatchers#assert_no_title}237 ##238 # Assertion that current path matches239 #240 # @!method assert_current_path241 # see {Capybara::SessionMatchers#assert_current_path}242 ##243 # Assertion that current page does not match244 #245 # @!method refute_current_path246 # @!method assert_no_current_path247 # see {Capybara::SessionMatchers#assert_no_current_path}248 private249 def determine_subject(args)250 case args.first251 when Capybara::Session, Capybara::Node::Base, Capybara::Node::Simple252 args253 else254 [page, *args]255 end256 end257 end258 end259end...
determine_subject
Using AI Code Generation
1 if self.respond_to?(:subject)2 elsif self.respond_to?(:model)3 if self.respond_to?(:subject)4 elsif self.respond_to?(:model)5 if self.respond_to?(:subject)6 elsif self.respond_to?(:model)7 if self.respond_to?(:subject)8 elsif self.respond_to?(:model)
determine_subject
Using AI Code Generation
1 Capybara::Minitest::Assertions.determine_subject(self)2 Capybara::Minitest::Assertions.determine_subject(self.class)3 Capybara::Minitest::Assertions.determine_subject(self.class, self)
determine_subject
Using AI Code Generation
1 self.method(:name).call2 self.instance_variable_get(:@name)3 self.instance_variable_get(:@method_name)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!