Skip to content

Instantly share code, notes, and snippets.

@alfius
Last active December 16, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfius/5454603 to your computer and use it in GitHub Desktop.
Save alfius/5454603 to your computer and use it in GitHub Desktop.
How to create an RSpec matcher that allows testing whether a page is indexable by search engines or not.
#spec/features/home_spec.rb
require 'spec_helper'
describe 'Home page' do
it 'should be searchable' do
visit '/'
page.should be_searchable
end
end
#spec/support/searchability.rb
RSpec::Matchers::define :be_searchable do
match do |page|
!page.has_selector?('meta[name="robots"][content="noindex,nofollow"]', :visible => false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment