From bb8bf74d9a0fa6ca98f158d465ca8544502b1536 Mon Sep 17 00:00:00 2001 From: Oriol Gual Date: Sat, 26 Jun 2010 22:35:22 +0200 Subject: [PATCH] Added Gemfile and bootrapped cucumber --- .gitignore | 4 +- Gemfile | 33 ++++ Rakefile | 4 +- features/rlacaixa.feature | 17 +- features/step_definitions/common_steps.rb | 4 + features/step_definitions/web_steps.rb | 201 ++++++++++++++++++++++ features/support/env.rb | 15 +- 7 files changed, 264 insertions(+), 14 deletions(-) create mode 100644 Gemfile create mode 100644 features/step_definitions/common_steps.rb create mode 100644 features/step_definitions/web_steps.rb diff --git a/.gitignore b/.gitignore index c1e0daf..bea96d8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,11 +11,13 @@ tmtags .\#* ## VIM -*.swp +*.sw? ## PROJECT::GENERAL coverage rdoc pkg +.bundle +Gemfile.lock ## PROJECT::SPECIFIC diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..aff119f --- /dev/null +++ b/Gemfile @@ -0,0 +1,33 @@ +source 'http://rubygems.org' +# gem 'rails', :git=>'git://github.com/rails/rails.git' +#gem 'delayed_job' + +group :development do + gem 'git-pivotal', :git => "http://github.com/trydionel/git-pivotal.git" + gem 'slurper' + gem "sqlite3-ruby", '1.2.5' + gem "jeweler" +end + +group :test do + # Latest rspec (2.0 beta) + gem "rspec", ">= 2.0.0.beta.13", :git => "http://github.com/rspec/rspec.git" + gem "rspec-rails", ">= 2.0.0.beta.13", :git => "http://github.com/rspec/rspec-rails.git" + gem "rspec-expectations", ">= 2.0.0.beta.13", :git => "http://github.com/rspec/rspec-expectations.git" + gem "rspec-core", ">= 2.0.0.beta.13", :git => "http://github.com/rspec/rspec-core.git" + gem "rspec-mocks", ">= 2.0.0.beta.13", :git => "http://github.com/rspec/rspec-mocks.git" + # Cucumber gems + gem "capybara" + gem 'capybara-envjs', :require => 'capybara/envjs' + gem "pickle", :git => "git://github.com/codegram/pickle" + gem 'autotest-rails' + gem "cucumber" + gem "cucumber-rails" + gem 'autotest' + gem 'autotest-growl' + gem "webrat" + + gem 'remarkable', '=4.0.0.alpha4' +end + +gem "factory_girl", :require=>false, :git => "git://github.com/thoughtbot/factory_girl.git", :branch => 'rails3' diff --git a/Rakefile b/Rakefile index 06bec9e..e171cf4 100644 --- a/Rakefile +++ b/Rakefile @@ -8,10 +8,10 @@ begin gem.summary = %Q{Parser for la Caixa} gem.description = %Q{Parser for la Caixa} gem.email = "info@codegram.com" - gem.homepage = "http://github.com/txus/rlacaixa" + gem.homepage = "http://github.com/codegram/rlacaixa" gem.authors = ["Oriol Gual", "Josep MÂȘ Bach", "Josep Jaume Rey"] - gem.add_development_dependency "rspec", ">= 2.0.0.beta.11" + gem.add_development_dependency "rspec", ">= 2.0.0.beta.12" gem.add_development_dependency "cucumber", ">= 0" end Jeweler::GemcutterTasks.new diff --git a/features/rlacaixa.feature b/features/rlacaixa.feature index b908b60..5bcf48a 100644 --- a/features/rlacaixa.feature +++ b/features/rlacaixa.feature @@ -1,9 +1,10 @@ -Feature: something something - In order to something something - A user something something - something something something +Feature: Log to your account + In order to retrieve my bank account information + As a customer + I want to enter my ID and password - Scenario: something something - Given inspiration - When I create a sweet new gem - Then everyone should see how awesome I am + Scenario: Log in with user and password + Given I visit LaCaixa website + And I follow "Particulares" + When I enter a valid ID and password + Then I should see my name diff --git a/features/step_definitions/common_steps.rb b/features/step_definitions/common_steps.rb new file mode 100644 index 0000000..384a4be --- /dev/null +++ b/features/step_definitions/common_steps.rb @@ -0,0 +1,4 @@ +# "Then I should see 5 articles" +Then /^I should see (\d+) (.+)$/ do |number, name| + assert page.has_xpath?("//*[@class = '#{name.singularize}']", :count => number.to_i) +end diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb new file mode 100644 index 0000000..2eca899 --- /dev/null +++ b/features/step_definitions/web_steps.rb @@ -0,0 +1,201 @@ +# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file +# instead of editing this one. Cucumber will automatically load all features/**/*.rb +# files. + + +require 'uri' + +module WithinHelpers + def with_scope(locator) + locator ? within(locator) { yield } : yield + end +end +World(WithinHelpers) + +Given /^(?:|I )am on (.+)$/ do |page_name| + visit page_name +end + +When /^(?:|I )go to (.+)$/ do |page_name| + visit page_name +end + +When /^(?:|I )press "([^\"]*)"(?: within "([^\"]*)")?$/ do |button, selector| + with_scope(selector) do + click_button(button) + end +end + +When /^(?:|I )follow "([^\"]*)"(?: within "([^\"]*)")?$/ do |link, selector| + with_scope(selector) do + click_link(link) + end +end + +When /^(?:|I )fill in "([^\"]*)" with "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, value, selector| + with_scope(selector) do + fill_in(field, :with => value) + end +end + +When /^(?:|I )fill in "([^\"]*)" for "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector| + with_scope(selector) do + fill_in(field, :with => value) + end +end + +# Use this to fill in an entire form with data from a table. Example: +# +# When I fill in the following: +# | Account Number | 5002 | +# | Expiry date | 2009-11-01 | +# | Note | Nice guy | +# | Wants Email? | | +# +# TODO: Add support for checkbox, select og option +# based on naming conventions. +# +When /^(?:|I )fill in the following(?: within "([^\"]*)")?:$/ do |selector, fields| + with_scope(selector) do + fields.rows_hash.each do |name, value| + When %{I fill in "#{name}" with "#{value}"} + end + end +end + +When /^(?:|I )select "([^\"]*)" from "([^\"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector| + with_scope(selector) do + select(value, :from => field) + end +end + +When /^(?:|I )check "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector| + with_scope(selector) do + check(field) + end +end + +When /^(?:|I )uncheck "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector| + with_scope(selector) do + uncheck(field) + end +end + +When /^(?:|I )choose "([^\"]*)"(?: within "([^\"]*)")?$/ do |field, selector| + with_scope(selector) do + choose(field) + end +end + +When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector| + with_scope(selector) do + attach_file(field, path) + end +end + +Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector| + with_scope(selector) do + if defined?(Spec::Rails::Matchers) + page.should have_content(text) + else + assert page.has_content?(text) + end + end +end + +Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector| + regexp = Regexp.new(regexp) + with_scope(selector) do + if defined?(Spec::Rails::Matchers) + page.should have_xpath('//*', :text => regexp) + else + assert page.has_xpath?('//*', :text => regexp) + end + end +end + +Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector| + with_scope(selector) do + if defined?(Spec::Rails::Matchers) + page.should have_no_content(text) + else + assert page.has_no_content?(text) + end + end +end + +Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^\"]*)")?$/ do |regexp, selector| + regexp = Regexp.new(regexp) + with_scope(selector) do + if defined?(Spec::Rails::Matchers) + page.should have_no_xpath('//*', :text => regexp) + else + assert page.has_no_xpath?('//*', :text => regexp) + end + end +end + +Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should contain "([^\"]*)"$/ do |field, selector, value| + with_scope(selector) do + if defined?(Spec::Rails::Matchers) + find_field(field).value.should =~ /#{value}/ + else + assert_match(/#{value}/, field_labeled(field).value) + end + end +end + +Then /^the "([^\"]*)" field(?: within "([^\"]*)")? should not contain "([^\"]*)"$/ do |field, selector, value| + with_scope(selector) do + if defined?(Spec::Rails::Matchers) + find_field(field).value.should_not =~ /#{value}/ + else + assert_no_match(/#{value}/, find_field(field).value) + end + end +end + +Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should be checked$/ do |label, selector| + with_scope(selector) do + if defined?(Spec::Rails::Matchers) + find_field(label)['checked'].should == 'checked' + else + assert_equal 'checked', field_labeled(label)['checked'] + end + end +end + +Then /^the "([^\"]*)" checkbox(?: within "([^\"]*)")? should not be checked$/ do |label, selector| + with_scope(selector) do + if defined?(Spec::Rails::Matchers) + find_field(label)['checked'].should_not == 'checked' + else + assert_not_equal 'checked', field_labeled(label)['checked'] + end + end +end + +Then /^(?:|I )should be on (.+)$/ do |page_name| + if defined?(Spec::Rails::Matchers) + URI.parse(current_url).path.should == path_to(page_name) + else + assert_equal path_to(page_name), URI.parse(current_url).path + end +end + +Then /^(?:|I )should have the following query string:$/ do |expected_pairs| + actual_params = CGI.parse(URI.parse(current_url).query) + expected_params = Hash[expected_pairs.rows_hash.map{|k,v| [k,[v]]}] + + if defined?(Spec::Rails::Matchers) + actual_params.should == expected_params + else + assert_equal expected_params, actual_params + end +end + +Then /^show me the page$/ do + save_and_open_page +end diff --git a/features/support/env.rb b/features/support/env.rb index 26ef478..8e39dfc 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,4 +1,13 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib') -require 'rlacaixa' +require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support +require 'cucumber/web/tableish' + +require 'capybara/cucumber' +require 'capybara/session' +require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript +# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In +# order to ease the transition to Capybara we set the default here. If you'd +# prefer to use XPath just remove this line and adjust any selectors in your +# steps to use the XPath syntax. +Capybara.default_selector = :css +Capybara.javascript_driver = :envjs -require 'rspec/expectations'