Skip to content

Instantly share code, notes, and snippets.

@mattheworiordan
Created April 16, 2011 17:05
Show Gist options
  • Save mattheworiordan/923298 to your computer and use it in GitHub Desktop.
Save mattheworiordan/923298 to your computer and use it in GitHub Desktop.
gemfile for RSpec
describe "the signup process", :type => :request do
it "signs me in", :js => true, :driver => :selenium do
visit calculator_path
within("#calculator") do
click_button '1'
end
end
end
describe "the calculator", :type => :request do
it "has buttons added by Javascript", :js => true do
visit calculator_path
within("#calculator") do
click_button '1'
end
end
it "has a calculator object in the global space", :driver => :selenium do
visit calculator_path
within("#calculator") do
click_button '1'
end
page.evaluate_script('$("#calculator").data("engine").sum(1,2)').should eql(3)
end
end
describe "the calculator", :type => :request do
it "has buttons added by Javascript", :js => true, :driver => :selenium do
Capybara.current_driver = :selenium # Force Capybara to switch drivers at this point
visit calculator_path
within("#calculator") do
click_button '1'
end
end
end
@javascript
Scenario: Use the Javascript based functions
Given I am on the calculator page
When I press "2"
And I press "5"
And I press "+"
Then I should see "25" within ".value"
When I press "√"
Then I should see "5" within ".value"
@selenium
Scenario: Test a JQuery UI dialog
Given I am on the calculator page
When I press "2"
And I press "+"
Then I should see "2" within ".value"
When I press "C"
Then I should see "Are you sure you want to clear the calculator and history?" within "#dialog-confirm"
When I press "Yes"
Then I should see "0" within ".value"
And I should not see "2" within ".history"
require 'selenium/client'
Capybara.javascript_driver = :akephalos
gem 'spork', '~> 0.9.0.rc'
gem 'akephalos'
gem 'selenium'
gem 'selenium-client'
class JavascriptTestController < ApplicationController
layout 'javascript_test'
before_filter :ensure_suitable_environment
def render_test
render :layout => 'javascript_test', :template => "../../spec/javascript/#{params[:script].gsub(/[^A-Za-z0-9_-]/,'')}_spec.js", :content_type => 'text/html'
end
private
def ensure_suitable_environment
render :status => :forbidden unless ['development','test'].include?(Rails.env)
end
end
page.evaluate_script('$("#calculator").data("engine").sum(1,2)').should eql(3)
$spec_cmd = "rspec --tty --drb --colour --format nested"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment