Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Update Signal #10

Open
wants to merge 6 commits into from

2 participants

Ricardo Almeida Duke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 11, 2011
  1. Ricardo Almeida

    updating cucumber

    ricardoalmeida authored
  2. Ricardo Almeida
Commits on Apr 12, 2011
  1. Ricardo Almeida
  2. Ricardo Almeida
  3. Ricardo Almeida

    coverage

    ricardoalmeida authored
Commits on Apr 14, 2011
  1. Ricardo Almeida

    build script

    ricardoalmeida authored
This page is out of date. Refresh to see the latest.
8 Gemfile
View
@@ -22,6 +22,13 @@ group :development, :test do
gem 'rspec', '>=2.0.1'
gem 'rspec-rails', '>=2.0.1'
gem "factory_girl_rails"
+ platforms :mri_18 do
+ gem "ruby-debug"
+ end
+
+ platforms :mri_19 do
+ gem "ruby-debug19"
+ end
end
group :test do
@@ -37,6 +44,7 @@ group :cucumber do
gem 'cucumber-rails'
gem 'database_cleaner'
gem 'capybara'
+ gem "launchy"
gem 'spork', ">=0.8.4"
gem "pickle", ">=0.4.2"
end
27 Gemfile.lock
View
@@ -29,6 +29,7 @@ GEM
activemodel (= 3.0.6)
activesupport (= 3.0.6)
activesupport (3.0.6)
+ archive-tar-minitar (0.5.2)
arel (2.0.9)
arrayfields (4.7.4)
babosa (0.3.3)
@@ -54,8 +55,10 @@ GEM
ruby_parser (~> 2.0.4)
sexp_processor (~> 3.0.3)
colored (1.2)
+ columnize (0.3.2)
compass (0.10.6)
haml (>= 3.0.4)
+ configuration (1.2.0)
cucumber (0.10.2)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
@@ -112,9 +115,15 @@ GEM
inploy (1.9.1)
json (1.5.1)
json_pure (1.5.1)
+ launchy (0.4.0)
+ configuration (>= 0.0.5)
+ rake (>= 0.8.1)
less (1.2.21)
mutter (>= 0.4.2)
treetop (>= 1.4.2)
+ linecache (0.43)
+ linecache19 (0.5.12)
+ ruby_core_source (>= 0.1.4)
mail (2.2.15)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@@ -203,10 +212,25 @@ GEM
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.5.0)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+ ruby-debug-base19 (0.11.25)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
ruby-progressbar (0.0.9)
ruby2ruby (1.2.5)
ruby_parser (~> 2.0)
sexp_processor (~> 3.0)
+ ruby_core_source (0.1.5)
+ archive-tar-minitar (>= 0.5.2)
ruby_parser (2.0.6)
sexp_processor (~> 3.0)
rubyzip (0.9.4)
@@ -253,6 +277,7 @@ DEPENDENCIES
hoptoad_notifier
inherited_resources (>= 1.1.2)
inploy (>= 1.9)
+ launchy
metric_fu
more (= 0.0.3)
mysql
@@ -264,6 +289,8 @@ DEPENDENCIES
remarkable_activerecord (>= 4.0.0.alpha4)
rspec (>= 2.0.1)
rspec-rails (>= 2.0.1)
+ ruby-debug
+ ruby-debug19
spork (>= 0.8.4)
sqlite3-ruby
webrat
8 app/views/projects/edit.html.haml
View
@@ -1,3 +1,9 @@
= semantic_form_for @project do |form|
- = form.inputs :name, :url, :email, :branch, :deploy_command, :build_command
+ = form.inputs do
+ = form.input :name
+ = form.input :url, :as => "string"
+ = form.input :email
+ = form.input :branch
+ = form.input :deploy_command
+ = form.input :build_command
= form.buttons
8 app/views/projects/new.html.haml
View
@@ -1,3 +1,9 @@
= semantic_form_for @project do |form|
- = form.inputs :name, :url, :email, :branch, :deploy_command, :build_command
+ = form.inputs do
+ = form.input :name
+ = form.input :url, :as => "string"
+ = form.input :email
+ = form.input :branch
+ = form.input :deploy_command
+ = form.input :build_command
= form.buttons
2  build.sh
View
@@ -0,0 +1,2 @@
+bundle install ~/.bundle --without=production
+rake build
2  config/cucumber.yml
View
@@ -1,7 +1,7 @@
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
-std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
+std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: --drb <%= std_opts %> features
wip: --drb --tags @wip:3 --wip features
8 features/manage_project.feature
View
@@ -5,12 +5,16 @@ Feature: Manage projects
Then I should not see /Building/
When I fill in "project_name" with "Geni"
- And I fill in "project_url" with "git://fake"
+ And I fill in "project_url" with "git@fake.com:gonow/fake"
And I fill in "project_email" with "fake@too.com"
And I press "Create Project"
Then a new project should be created
And I should see /Geni/
+ Scenario: Browsers with HTML5 support
+ Given I am on the new projects page
+ Then I should see url field with type text
+
Scenario: Update a project
Given I have a project
And I am on the edit project page
@@ -56,5 +60,5 @@ Feature: Manage projects
And I should receive a link for the feed of the project
When I request '/projects.rss'
Then I should see the name of the project
- When I request '/projects/1.rss'
+ When I request '/projects/1.rss' for created project
Then I should see the name of the project
8 features/step_definitions/projects_steps.rb
View
@@ -10,6 +10,10 @@
visit path
end
+When /^I request '(.*)' for created project$/ do |path|
+ visit path.gsub("1", "#{@project.id}")
+end
+
When /^a new project should be created$/ do
Project.count.should == 1
end
@@ -45,3 +49,7 @@
Then /^I should receive a link for the feed of the project$/ do
page.should have_xpath("//link[@type='application/rss+xml'][@href='/projects/#{@project.name}.rss'][@title='#{@project.name}']")
end
+
+Then /^I should see url field with type text$/ do
+ find(:xpath, '//*[@id="project_url" and @type="text"]').should_not raise_exception(Capybara::ElementNotFound)
+end
172 features/step_definitions/web_steps.rb
View
@@ -1,21 +1,46 @@
-# 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.
+# TL;DR: YOU SHOULD DELETE THIS FILE
+#
+# This file was generated by Cucumber-Rails and is only here to get you a head start
+# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
+# visit pages, interact with widgets and make assertions about page content.
+#
+# If you use these step definitions as basis for your features you will quickly end up
+# with features that are:
+#
+# * Hard to maintain
+# * Verbose to read
+#
+# A much better approach is to write your own higher level step definitions, following
+# the advice in the following blog posts:
+#
+# * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
+# * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
+# * http://elabs.se/blog/15-you-re-cuking-it-wrong
+#
require 'uri'
require 'cgi'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
module WithinHelpers
def with_scope(locator)
- locator ? within(locator) { yield } : yield
+ locator ? within(*selector_for(locator)) { yield } : yield
end
end
World(WithinHelpers)
+# Single-line step scoper
+When /^(.*) within ([^:]+)$/ do |step, parent|
+ with_scope(parent) { When step }
+end
+
+# Multi-line step scoper
+When /^(.*) within ([^:]+):$/ do |step, parent, table_or_string|
+ with_scope(parent) { When "#{step}:", table_or_string }
+end
+
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end
@@ -24,28 +49,20 @@ def with_scope(locator)
visit path_to(page_name)
end
-When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
- with_scope(selector) do
- click_button(button)
- end
+When /^(?:|I )press "([^"]*)"$/ do |button|
+ click_button(button)
end
-When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
- with_scope(selector) do
- click_link(link)
- end
+When /^(?:|I )follow "([^"]*)"$/ do |link|
+ click_link(link)
end
-When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
- with_scope(selector) do
- fill_in(field, :with => value)
- end
+When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
+ fill_in(field, :with => value)
end
-When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
- with_scope(selector) do
- fill_in(field, :with => value)
- end
+When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
+ fill_in(field, :with => value)
end
# Use this to fill in an entire form with data from a table. Example:
@@ -59,95 +76,70 @@ def with_scope(locator)
# 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)
+When /^(?:|I )fill in the following:$/ do |fields|
+ fields.rows_hash.each do |name, value|
+ When %{I fill in "#{name}" with "#{value}"}
end
end
-When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
- with_scope(selector) do
- check(field)
- end
+When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
+ select(value, :from => field)
end
-When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
- with_scope(selector) do
- uncheck(field)
- end
+When /^(?:|I )check "([^"]*)"$/ do |field|
+ check(field)
end
-When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
- with_scope(selector) do
- choose(field)
- end
+When /^(?:|I )uncheck "([^"]*)"$/ do |field|
+ uncheck(field)
end
-When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
- with_scope(selector) do
- attach_file(field, path)
- end
+When /^(?:|I )choose "([^"]*)"$/ do |field|
+ choose(field)
end
-Then /^(?:|I )should see JSON:$/ do |expected_json|
- require 'json'
- expected = JSON.pretty_generate(JSON.parse(expected_json))
- actual = JSON.pretty_generate(JSON.parse(response.body))
- expected.should == actual
+When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
+ attach_file(field, File.expand_path(path))
end
-Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
- with_scope(selector) do
- if page.respond_to? :should
- page.should have_content(text)
- else
- assert page.has_content?(text)
- end
+Then /^(?:|I )should see "([^"]*)"$/ do |text|
+ if page.respond_to? :should
+ page.should have_content(text)
+ else
+ assert page.has_content?(text)
end
end
-Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
+Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
regexp = Regexp.new(regexp)
- with_scope(selector) do
- if page.respond_to? :should
- page.should have_xpath('//*', :text => regexp)
- else
- assert page.has_xpath?('//*', :text => regexp)
- end
+
+ if page.respond_to? :should
+ page.should have_xpath('//*', :text => regexp)
+ else
+ assert page.has_xpath?('//*', :text => regexp)
end
end
-Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
- with_scope(selector) do
- if page.respond_to? :should
- page.should have_no_content(text)
- else
- assert page.has_no_content?(text)
- end
+Then /^(?:|I )should not see "([^"]*)"$/ do |text|
+ if page.respond_to? :should
+ page.should have_no_content(text)
+ else
+ assert page.has_no_content?(text)
end
end
-Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
+Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
regexp = Regexp.new(regexp)
- with_scope(selector) do
- if page.respond_to? :should
- page.should have_no_xpath('//*', :text => regexp)
- else
- assert page.has_no_xpath?('//*', :text => regexp)
- end
+
+ if page.respond_to? :should
+ page.should have_no_xpath('//*', :text => regexp)
+ else
+ assert page.has_no_xpath?('//*', :text => regexp)
end
end
-Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
- with_scope(selector) do
+Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
+ with_scope(parent) do
field = find_field(field)
field_value = (field.tag_name == 'textarea') ? field.text : field.value
if field_value.respond_to? :should
@@ -158,8 +150,8 @@ def with_scope(locator)
end
end
-Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
- with_scope(selector) do
+Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
+ with_scope(parent) do
field = find_field(field)
field_value = (field.tag_name == 'textarea') ? field.text : field.value
if field_value.respond_to? :should_not
@@ -170,8 +162,8 @@ def with_scope(locator)
end
end
-Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
- with_scope(selector) do
+Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
+ with_scope(parent) do
field_checked = find_field(label)['checked']
if field_checked.respond_to? :should
field_checked.should be_true
@@ -181,8 +173,8 @@ def with_scope(locator)
end
end
-Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
- with_scope(selector) do
+Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
+ with_scope(parent) do
field_checked = find_field(label)['checked']
if field_checked.respond_to? :should
field_checked.should be_false
72 features/support/env.rb
View
@@ -1,27 +1,19 @@
# 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
+# 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 'rubygems'
require 'spork'
+require 'capybara'
+require 'capybara/dsl'
+
Spork.prefork do
- ENV["RAILS_ENV"] ||= "test"
- require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
+ require 'cucumber/rails'
- require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
- require 'cucumber/rails/rspec'
- require 'cucumber/rails/world'
- require 'cucumber/rails/active_record'
- require 'cucumber/web/tableish'
-
- require 'capybara/rails'
- 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
@@ -29,39 +21,31 @@
Capybara.default_selector = :css
end
-
+
Spork.each_run do
- # If you set this to false, any error raised from within your app will bubble
- # up to your step definition and out to cucumber unless you catch it somewhere
- # on the way. You can make Rails rescue errors and render error pages on a
- # per-scenario basis by tagging a scenario or feature with the @allow-rescue tag.
+ # By default, any exception happening in your Rails application will bubble up
+ # to Cucumber so that your scenario will fail. This is a different from how
+ # your application behaves in the production environment, where an error page will
+ # be rendered instead.
#
- # If you set this to true, Rails will rescue all errors and render error
- # pages, more or less in the same way your application would behave in the
- # default production environment. It's not recommended to do this for all
- # of your scenarios, as this makes it hard to discover errors in your application.
- ActionController::Base.allow_rescue = false
-
- # If you set this to true, each scenario will run in a database transaction.
- # You can still turn off transactions on a per-scenario basis, simply tagging
- # a feature or scenario with the @no-txn tag. If you are using Capybara,
- # tagging with @culerity or @javascript will also turn transactions off.
+ # Sometimes we want to override this default behaviour and allow Rails to rescue
+ # exceptions and display an error page (just like when the app is running in production).
+ # Typical scenarios where you want to do this is when you test your error pages.
+ # There are two ways to allow Rails to rescue exceptions:
#
- # If you set this to false, transactions will be off for all scenarios,
- # regardless of whether you use @no-txn or not.
+ # 1) Tag your scenario (or feature) with @allow-rescue
#
- # Beware that turning transactions off will leave data in your database
- # after each scenario, which can lead to hard-to-debug failures in
- # subsequent scenarios. If you do this, we recommend you create a Before
- # block that will explicitly put your database in a known state.
- Cucumber::Rails::World.use_transactional_fixtures = true
- # How to clean your database when transactions are turned off. See
- # http://github.com/bmabey/database_cleaner for more info.
- if defined?(ActiveRecord::Base)
- begin
- require 'database_cleaner'
- DatabaseCleaner.strategy = :truncation
- rescue LoadError => ignore_if_database_cleaner_not_present
- end
+ # 2) Set the value below to true. Beware that doing this globally is not
+ # recommended as it will mask a lot of errors for you!
+ #
+ ActionController::Base.allow_rescue = false
+
+ # Remove/comment out the lines below if your app doesn't have a database.
+ # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
+ begin
+ DatabaseCleaner.strategy = :transaction
+ rescue NameError
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
+
end
39 features/support/selectors.rb
View
@@ -0,0 +1,39 @@
+module HtmlSelectorsHelpers
+ # Maps a name to a selector. Used primarily by the
+ #
+ # When /^(.+) within (.+)$/ do |step, scope|
+ #
+ # step definitions in web_steps.rb
+ #
+ def selector_for(locator)
+ case locator
+
+ when /the page/
+ "html > body"
+
+ # Add more mappings here.
+ # Here is an example that pulls values out of the Regexp:
+ #
+ # when /the (notice|error|info) flash/
+ # ".flash.#{$1}"
+
+ # You can also return an array to use a different selector
+ # type, like:
+ #
+ # when /the header/
+ # [:xpath, "//header"]
+
+ # This allows you to provide a quoted selector as the scope
+ # for "within" steps as was previously the default for the
+ # web steps:
+ when /"(.+)"/
+ $1
+
+ else
+ raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
+ "Now, go and add a mapping in #{__FILE__}"
+ end
+ end
+end
+
+World(HtmlSelectorsHelpers)
4 lib/tasks/cucumber.rake
View
@@ -43,6 +43,10 @@ begin
task :features => :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
end
+
+ # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
+ task 'db:test:prepare' do
+ end
rescue LoadError
desc 'cucumber rake task not available (cucumber not installed)'
task :cucumber do
8 spec/models/project_spec.rb
View
@@ -46,6 +46,7 @@
expect_for "cd #{subject.send :path} && rake inploy:local:setup >> #{subject.send :log_path} 2>&1"
subject.save
end
+
end
context "on #build" do
@@ -155,6 +156,13 @@
subject.branch.should eql("master")
end
+ context "on destroy" do
+ it "should execute rm -rf" do
+ subject.should_receive(:execute).with("rm -rf /Users/ricardoalmeida/Documents/projects/gonow/signal/public/projects/")
+ subject.destroy
+ end
+ end
+
context "on has_file?" do
it "should return true if the project has the file path" do
file_exists(subject.send(:path) + '/doc/specs.html')
Something went wrong with that request. Please try again.