Skip to content

Commit

Permalink
Refactor HaveAReturnField and HaveAnInputField away entirely.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronklaassen committed May 10, 2017
1 parent 976e638 commit bfea3e2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 45 deletions.
16 changes: 7 additions & 9 deletions lib/rspec/graphql_matchers/have_a_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
module RSpec
module GraphqlMatchers
class HaveAField < BaseMatcher
def initialize(expected_field_name)
def initialize(expected_field_name, fields = :fields)
@expected_field_name = expected_field_name.to_s
@expected_field_type = @graph_object = nil
@fields = :fields
@fields = fields.to_sym
end

def matches?(graph_object)
Expand Down Expand Up @@ -73,13 +73,11 @@ def field_collection
end

def matcher_name
klass = self.class.to_s.split('::').last

# Copied these from: https://github.com/rails/rails/blob/v4.2.7.1/activesupport/lib/active_support/inflector/methods.rb#L95-L96
klass.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
klass.gsub!(/([a-z\d])([A-Z])/, '\1_\2')

klass.downcase!
case @fields
when :fields then 'have_a_field'
when :input_fields then 'have_an_input_field'
when :return_fields then 'have_a_return_field'
end
end
end
end
Expand Down
16 changes: 0 additions & 16 deletions lib/rspec/graphql_matchers/have_a_return_field.rb

This file was deleted.

16 changes: 0 additions & 16 deletions lib/rspec/graphql_matchers/have_an_input_field.rb

This file was deleted.

6 changes: 2 additions & 4 deletions lib/rspec/graphql_matchers/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
require 'rspec/graphql_matchers/be_of_type'
require 'rspec/graphql_matchers/accept_arguments'
require 'rspec/graphql_matchers/have_a_field'
require 'rspec/graphql_matchers/have_an_input_field'
require 'rspec/graphql_matchers/have_a_return_field'

module RSpec
module Matchers
Expand All @@ -24,13 +22,13 @@ def have_a_field(field_name)

# rubocop:disable Style/PredicateName
def have_an_input_field(field_name)
RSpec::GraphqlMatchers::HaveAnInputField.new(field_name)
RSpec::GraphqlMatchers::HaveAField.new(field_name, :input_fields)
end
alias have_input_field have_an_input_field

# rubocop:disable Style/PredicateName
def have_a_return_field(field_name)
RSpec::GraphqlMatchers::HaveAReturnField.new(field_name)
RSpec::GraphqlMatchers::HaveAField.new(field_name, :return_fields)
end
alias have_return_field have_a_return_field
end
Expand Down

0 comments on commit bfea3e2

Please sign in to comment.