Skip to content

Commit

Permalink
add graphql rspec helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlindsey committed Nov 17, 2020
1 parent 1400793 commit 2e8150a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 4 additions & 5 deletions spec/graphql/queries/show_event_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'rails_helper'
require 'graphql_helper'

RSpec.describe 'Events' do

Expand All @@ -20,10 +21,8 @@
GRAPHQL

result = WebsiteOneBackendApiSchema.execute(query_string)["data"]["events"]

names = result.collect {|x| x["name"]}

assert names.detect { |e| e == 'FirstEvent' }
assert names.detect { |e| e == 'AnotherEvent' }

expect(result).to json_contains('FirstEvent', 'name')
expect(result).to json_contains('AnotherEvent', 'name')
end
end
6 changes: 6 additions & 0 deletions spec/graphql_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RSpec::Matchers.define :json_contains do |expected, key|
match do |actual|
a = actual.collect {|x| x[key]}
a.detect { |e| e == expected }
end
end

0 comments on commit 2e8150a

Please sign in to comment.