Skip to content

Instantly share code, notes, and snippets.

@danielmorrison
danielmorrison / gist:1186144
Created September 1, 2011 13:16 — forked from bryckbost/gist:1040263
Capybara 1.0 and Chrome
# env.rb
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.javascript_driver = :chrome
Download chromedriver from http://code.google.com/p/selenium/downloads/list
@danielmorrison
danielmorrison / dates.rb
Created March 26, 2011 19:35
Problems with Date.parse
# Ruby 1.8.7
> Date.parse('01/06/2010').to_s
=> "2010-06-01"
# Ruby 1.9.2
> Date.parse('01/06/2010').to_s
=> "2010-01-06"
def csrf_meta_tags
if protect_against_forgery?
[].tap do |tags|
tags << tag('meta', {:name => 'csrf-param', :content => request_forgery_protection_token})
tags << tag('meta', {:name => 'csrf-token', :content => form_authenticity_token})
end.join("\n").html_safe
end
end
@danielmorrison
danielmorrison / user_steps.rb
Created November 12, 2010 18:17
put in features/step_definitions/user_steps.rb
Given "I am signed in" do
user = User.create!(:email => 'alice@example.com', :password => 'password', :password_confirmation => 'password')
step 'I go to the homepage'
step 'I follow "Sign In"'
step %Q|I fill in "user_email" with "#{user.email}"|
step 'I fill in "user_password" with "password"'
step 'I press "Sign in"'
end
@danielmorrison
danielmorrison / gist:671304
Last active September 24, 2015 04:57
put inside auctions/new.html.erb
<% if form.object.errors.any? %>
<div id="error_explanation">
<h2>The following errors prohibited this form from being saved:</h2>
<ul>
<% form.object.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>eHarbor</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<%= csrf_meta_tag %>
<%= stylesheet_link_tag 'application', :media => "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag 'application', "data-turbolinks-track" => true %>
require 'test/unit'
require 'book'
class BookTest < Test::Unit::TestCase
def setup
@book = Book.new
end
def test_should_capitalize_the_first_letter
<!DOCTYPE html>
<html lang="en">
<head>
<title>eHarbor</title>
<%= stylesheet_link_tag 'boilerplate', 'main' %>
<%= javascript_include_tag :defaults %>
<!--[if IE]>
<%= javascript_include_tag 'http://html5shiv.googlecode.com/svn/trunk/html5.js' %>
<![endif]-->
</head>
When /I see wtf is going on/i do
save_and_open_page
end
When /I want to debug/i do
debugger
true # never put debugger at the end of a method
end
# just add a gem dependency for Timecop or require it yourself
Given 'the time is $time' do |time|
Timecop.freeze Time.parse(time)
end
When '$time pass' do |time|
Timecop.travel future_time(time)
Given 'delayed jobs are run' # we use delayed jobs and have some that get scheduled in the future.
end