Module: GraphQL::Compatibility::QueryParserSpecification::ParseErrorSpecification
- Defined in:
- lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb
Instance Method Summary collapse
-
#assert_raises_parse_error(query_string) ⇒ Object
-
#assert_rejects_character(char) ⇒ Object
-
#test_it_includes_line_and_column ⇒ Object
-
#test_it_rejects_bad_unicode ⇒ Object
-
#test_it_rejects_blank_queries ⇒ Object
-
#test_it_rejects_empty_inline_fragments ⇒ Object
-
#test_it_rejects_invalid_characters ⇒ Object
-
#test_it_rejects_unexpected_ends ⇒ Object
-
#test_it_rejects_unterminated_strings ⇒ Object
-
#test_it_restricts_on ⇒ Object
Instance Method Details
#assert_raises_parse_error(query_string) ⇒ Object
6 7 8 9 10 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 6 def assert_raises_parse_error(query_string) assert_raises(GraphQL::ParseError) { parse(query_string) } end |
#assert_rejects_character(char) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 33 def assert_rejects_character(char) err = assert_raises_parse_error("{ field#{char} }") expected_char = char.inspect.gsub('"', '').downcase msg_downcase = err..downcase # Case-insensitive for UTF-8 printing assert_includes(msg_downcase, expected_char, "The message includes the invalid character") end |
#test_it_includes_line_and_column ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 12 def test_it_includes_line_and_column err = assert_raises_parse_error(" query getCoupons { allCoupons: {data{id}} } ") assert_includes(err., '{') assert_equal(3, err.line) assert_equal(27, err.col) end |
#test_it_rejects_bad_unicode ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 50 def test_it_rejects_bad_unicode assert_raises_parse_error(%|{ field(arg:"\\x") }|) assert_raises_parse_error(%|{ field(arg:"\\u1") }|) assert_raises_parse_error(%|{ field(arg:"\\u0XX1") }|) assert_raises_parse_error(%|{ field(arg:"\\uXXXX") }|) assert_raises_parse_error(%|{ field(arg:"\\uFXXX") }|) assert_raises_parse_error(%|{ field(arg:"\\uXXXF") }|) end |
#test_it_rejects_blank_queries ⇒ Object
73 74 75 76 77 78 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 73 def test_it_rejects_blank_queries assert_raises_parse_error("") assert_raises_parse_error(" ") assert_raises_parse_error("\t \t") assert_raises_parse_error(" # comment ") end |
#test_it_rejects_empty_inline_fragments ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 59 def test_it_rejects_empty_inline_fragments assert_raises_parse_error(" query { viewer { login { ... on String { } } } } ") end |
#test_it_rejects_invalid_characters ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 41 def test_it_rejects_invalid_characters assert_rejects_character(";") assert_rejects_character("\a") assert_rejects_character("\xef") assert_rejects_character("\v") assert_rejects_character("\f") assert_rejects_character("\xa0") end |
#test_it_rejects_unexpected_ends ⇒ Object
29 30 31 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 29 def test_it_rejects_unexpected_ends assert_raises_parse_error("query { stuff { thing }") end |
#test_it_rejects_unterminated_strings ⇒ Object
24 25 26 27 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 24 def test_it_rejects_unterminated_strings assert_raises_parse_error('{ " }') assert_raises_parse_error(%|{ "\n" }|) end |
#test_it_restricts_on ⇒ Object
80 81 82 83 |
# File 'lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb', line 80 def test_it_restricts_on assert_raises_parse_error("{ ...on }") assert_raises_parse_error("fragment on on Type { field }") end |