How to use valid_types method of Queries Package

Best Capybara code snippet using Queries.valid_types

scaffold.rb

Source:scaffold.rb Github

copy

Full Screen

...363 unless model_name =~ /^[\p{L}_][\p{L}\p{N}@$#_]{0,127}$/364 puts "'#{model_name}' does not appear to be a valid."365 return366 end367 valid_types = %w(integer float string boolean date datetime decimal binary bigint primary_key references string text time timestamp)368 arguments.each do |arg|369 field_name, field_type = arg.split(':')370 unless field_name =~ /^[\p{L}_][\p{L}\p{N}@$#_]{0,127}$/371 puts "'#{field_name} does not appear to be valid'"372 return373 end374 unless valid_types.include?(field_type)375 puts "'#{field_type}' does not appear to be valid. Valid field types are: #{valid_types.join(', ')}"376 end377 end378 if generate_model(model_name, arguments) &&379 generate_types(model_name, arguments) &&380 generate_queries(model_name) &&381 generate_routes(model_name) &&382 generate_tests(model_name, arguments)383 puts "Done."384 else385 puts "Partially done."386 end387 end388 def generate_aaa389 model_name = 'user'...

Full Screen

Full Screen

text_query.rb

Source:text_query.rb Github

copy

Full Screen

...4 module Queries5 class TextQuery < BaseQuery6 def initialize(type = nil, expected_text, session_options:, **options) # rubocop:disable Style/OptionalArguments7 @type = type.nil? ? default_type : type8 raise ArgumentError, "#{@type} is not a valid type for a text query" unless valid_types.include?(@type)9 @options = options10 super(@options)11 self.session_options = session_options12 if expected_text.nil? && !exact?13 warn 'Checking for expected text of nil is confusing and/or pointless since it will always match. '\14 "Please specify a string or regexp instead. #{Capybara::Helpers.filter_backtrace(caller)}"15 end16 @expected_text = expected_text.is_a?(Regexp) ? expected_text : expected_text.to_s17 @search_regexp = Capybara::Helpers.to_regexp(@expected_text, exact: exact?)18 assert_valid_keys19 end20 def resolve_for(node)21 @node = node22 @actual_text = text23 @count = @actual_text.scan(@search_regexp).size24 end25 def failure_message26 super << build_message(true)27 end28 def negative_failure_message29 super << build_message(false)30 end31 def description32 if @expected_text.is_a?(Regexp)33 "text matching #{@expected_text.inspect}"34 else35 "#{'exact ' if exact?}text #{@expected_text.inspect}"36 end37 end38 private39 def exact?40 options.fetch(:exact, session_options.exact_text)41 end42 def build_message(report_on_invisible)43 message = +''44 unless (COUNT_KEYS & @options.keys).empty?45 message << " but found #{@count} #{Capybara::Helpers.declension('time', 'times', @count)}"46 end47 message << " in #{@actual_text.inspect}"48 details_message = []49 details_message << case_insensitive_message if @node && check_case_insensitive?50 details_message << invisible_message if @node && check_visible_text? && report_on_invisible51 details_message.compact!52 message << ". (However, #{details_message.join(' and ')}.)" unless details_message.empty?53 message54 end55 def case_insensitive_message56 insensitive_regexp = Capybara::Helpers.to_regexp(@expected_text, options: Regexp::IGNORECASE)57 insensitive_count = @actual_text.scan(insensitive_regexp).size58 return if insensitive_count == @count59 "it was found #{occurrences insensitive_count} using a case insensitive search"60 end61 def invisible_message62 invisible_text = text(query_type: :all)63 invisible_count = invisible_text.scan(@search_regexp).size64 return if invisible_count == @count65 "it was found #{occurrences invisible_count} including non-visible text"66 rescue StandardError67 # An error getting the non-visible text (if element goes out of scope) should not affect the response68 nil69 end70 def valid_keys71 COUNT_KEYS + %i[wait exact normalize_ws]72 end73 def valid_types74 %i[all visible]75 end76 def check_visible_text?77 @type == :visible78 end79 def check_case_insensitive?80 !@expected_text.is_a?(Regexp)81 end82 def text(node: @node, query_type: @type)83 normalize_ws = options.fetch(:normalize_ws, session_options.default_normalize_ws)84 node.text(query_type, normalize_ws: normalize_ws)85 end86 def default_type87 Capybara.ignore_hidden_elements || Capybara.visible_text_only ? :visible : :all...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful