Skip to content

Instantly share code, notes, and snippets.

View nruth's full-sized avatar

Nicholas Rutherford nruth

View GitHub Profile
Given I am on the page links page
When I follow "New Link"
Then I should be on the new page link page
When I fill in "Text" with "Fresh Fruit"
And I fill in "Path" with "fruit"
And I press "Create"
Then 1 page link should exist
When I go to the homepage
@nruth
nruth / alias_step.rb
Created November 20, 2009 18:27
Cucumber Step general alias for Then/When/Given
#defines Step, which is the generic When/Then/Given, since they actually have no meaning to cucumber, they're just fluff for human eyes
#written by Ian White, observed by yours truly
module AliasStep
def Step(arg)
When arg
end
end
World(AliasStep)
@nruth
nruth / dynamic_show_hide_help_boxes.feature
Created May 24, 2010 02:10
capybara hidden element has_content example
@ignore-hidden-elements
Feature: Div help content hiding and revealing
In order to keep help text available but neatly tucked away when not needed
As a designer
I want javascript to detect div.help and hide it and its contents, replacing with a link to reveal it again
Background:
#this is a rails app with a Page model and a path_to entry for visiting them in features like this (using Pickle for cucumber / machinist integration)
Given a page exists with content: "<div class='help'>foobar</div>"
Given /^#{capture_model} has a question: "([^\"]*)"$/ do |model_name, question|
model = model! model_name
store_model "question", '', model.questions.make(:question => question)
end
Given /^#{capture_model} has a question$/ do |model_name|
model = model! model_name
factory, name_or_index = *parse_model(%Q(question)) #pickle internals
store_model factory, name_or_index, model.questions.make
end
@nruth
nruth / Rakefile
Created July 18, 2010 17:11
Heroku bundle downloader -- just add cron
require 'rake'
APP_NAME = 'heroku_app_name'
BACKUP_PATH = '.'
namespace "heroku" do
desc "create a new Heroku bundle and download it, name with timestamp - only use with single bundle addon"
task "backup" do
require 'fileutils'
@nruth
nruth / clonetab.rb
Created July 18, 2010 20:25
OSX open new terminal tab @ current pwd
#!/usr/bin/env ruby
require 'fileutils'
extend FileUtils
cmd1 = "tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down"
cmd2 = "tell application \"Terminal\" to do script \"cd #{pwd}\" in the front window"
`osascript -e '#{cmd1}' -e '#{cmd2}'`
@nruth
nruth / cookie_steps.rb
Created July 21, 2010 17:16
Testing login "remember me" feature with Capybara (rack::test or selenium) - deleting the session cookie (only)
@nruth
nruth / tests_spec.rb
Created July 30, 2010 20:48
how not to loop/nest rspec example groups (where you want to iterate diferent let/before variable values)
class Tests
SUBTESTS = %w(Abstract Decision Quantitative Verbal)
end
describe Tests do
describe "before assigning @ - " do
describe "this doesn't work because the loops are all at the same describe level (the befores override one another)" do
Tests::SUBTESTS.each do |test|
before(:each) do
@nruth
nruth / gist:501517
Created July 30, 2010 23:54
rspec 1 before / let for context
describe "3 users exist"
let(:users) {(1..3).map {User.make}}
specify "user count should be 3" do
pending "this will fail because users hasn't been called" do
User.count.should == 3
end
end
specify "3 users should exist" do
@nruth
nruth / controller_spec.rb
Created August 21, 2010 16:32
Capybara rack-test response status code checking
describe "when some redirect mappings are present in the Medify::PAGE_REDIRECTS hash" do
before(:each) do
Medify::PAGE_REDIRECTS['/abstract-reasoning-subtest-advice-by-medify'] = '/advice-pages/abstract-reasoning-subtest-advice-by-medify'
Medify::PAGE_REDIRECTS['/decision-analysis-subtest-advice-by-medify'] = '/advice-pages/decision-analysis-subtest-advice-by-medify'
end
describe "GET :show, :path => abstract-reasoning-subtest-advice-by-medify" do
subject {get :show, :path => 'abstract-reasoning-subtest-advice-by-medify'}
it {should be_redirect}
it {should redirect_to('/advice-pages/abstract-reasoning-subtest-advice-by-medify')}