Skip to content

Instantly share code, notes, and snippets.

@ydnar
Created October 19, 2009 00:38
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 ydnar/212977 to your computer and use it in GitHub Desktop.
Save ydnar/212977 to your computer and use it in GitHub Desktop.
Test robots.txt with Cucumber & Robots
require 'robots'
# Cucumber steps for robots.txt
# Requires the robots gem: http://github.com/fizx/robots
# Note: url_for() returns a fully-qualified URL, similar to path_to()
When /^I am a robot named (.+)$/ do |user_agent|
@robots = Robots.new user_agent
end
When /^I should be allowed to request (.+)$/ do |page_name|
url = url_for(page_name)
@robots.allowed?(url).should be_true
end
When /^I should not be allowed to request (.+)$/ do |page_name|
url = url_for(page_name)
@robots.allowed?(url).should be_false
end
Feature: robots.txt
In order to limit access to certain pages by Google and other crawlers
I want to have a robots.txt file with certain URLs masked out
Scenario Outline: Allowed URLs
When I am a robot named Google
Then I should be allowed to request <resource>
Examples:
| resource |
| the home page |
| /foo-bar |
| /favicon.ico |
Scenario Outline: Disallowed URLs
When I am a robot named Google
Then I should not be allowed to request <resource>
Examples:
| resource |
| the dashboard |
| the edit page |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment