Skip to content

Instantly share code, notes, and snippets.

@dowglaz
Last active August 29, 2015 14:18
Show Gist options
  • Save dowglaz/476d0a207641bf577190 to your computer and use it in GitHub Desktop.
Save dowglaz/476d0a207641bf577190 to your computer and use it in GitHub Desktop.
Custom matcher example
# On spec/rails_helper.rb
...
config.include Matchers, type: :feature
...
# Separate spec/support/matchers/matchers.rb into two files:
# spec/support/matchers/tabs.rb
module Matchers
matcher :have_active_tab do |tab_name|
match do |page|
expect(page).to have_css(
'li[aria-controls="#{tab_name}"][aria-selected=true].ui-state-active'
)
end
end
matcher :have_inactive_tab do |tab_name|
match do |page|
expect(page).to have_css(
'li[aria-controls="#{tab_name}"][aria-selected=false]'
)
end
end
end
# and spec/support/matchers/uri.rb
module Matchers
matcher :have_query_string do |tab_name, options|
match do |url|
uri = URI.parse(url)
expect(uri.query).to include "#{tab_name}=#{options[:with]}"
end
end
end
# And the spec/support/matchers.rb
module Matchers
extend RSpec::Matchers::DSL
include Capybara::DSL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment