Skip to content

Commit

Permalink
All the test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
David Padilla committed Sep 13, 2010
1 parent cc874b8 commit 44bbfe2
Show file tree
Hide file tree
Showing 16 changed files with 612 additions and 1 deletion.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--colour
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ gem 'rails', '3.0.0'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'nifty-generators'
gem 'rails3-jquery-autocomplete'

group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'pickle'
gem 'machinist', '>= 2.0.0.beta2'
gem 'rspec-rails', '>=2.0.0.beta.20'
end
52 changes: 52 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,44 @@ GEM
arel (1.0.1)
activesupport (~> 3.0.0)
builder (2.1.2)
capybara (0.3.9)
culerity (>= 0.2.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (>= 0.0.3)
cucumber (0.8.5)
builder (~> 2.1.2)
diff-lcs (~> 1.1.2)
gherkin (~> 2.1.4)
json_pure (~> 1.4.3)
term-ansicolor (~> 1.0.4)
cucumber-rails (0.3.2)
cucumber (>= 0.8.0)
culerity (0.2.12)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
ffi (0.6.3)
rake (>= 0.8.7)
gherkin (2.1.5)
trollop (~> 1.16.2)
i18n (0.4.1)
json_pure (1.4.6)
machinist (2.0.0.beta2)
mail (2.2.6)
activesupport (>= 2.3.6)
mime-types
treetop (>= 1.4.5)
mime-types (1.16)
nifty-generators (0.4.0)
nokogiri (1.4.3.1)
pickle (0.4.2)
cucumber (>= 0.8)
rake
rspec (>= 1.3)
yard
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
Expand All @@ -61,17 +90,40 @@ GEM
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
rspec (2.0.0.beta.20)
rspec-core (= 2.0.0.beta.20)
rspec-expectations (= 2.0.0.beta.20)
rspec-mocks (= 2.0.0.beta.20)
rspec-core (2.0.0.beta.20)
rspec-expectations (2.0.0.beta.20)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.20)
rspec-rails (2.0.0.beta.20)
rspec (= 2.0.0.beta.20)
rubyzip (0.9.4)
selenium-webdriver (0.0.28)
ffi (>= 0.6.1)
json_pure
rubyzip
sqlite3-ruby (1.3.1)
term-ansicolor (1.0.5)
thor (0.14.0)
treetop (1.4.8)
polyglot (>= 0.3.1)
trollop (1.16.2)
tzinfo (0.3.23)
yard (0.6.1)

PLATFORMS
ruby

DEPENDENCIES
capybara
cucumber-rails
machinist (>= 2.0.0.beta2)
nifty-generators
pickle
rails (= 3.0.0)
rails3-jquery-autocomplete
rspec-rails (>= 2.0.0.beta.20)
sqlite3-ruby
2 changes: 2 additions & 0 deletions autotest/discover.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Autotest.add_discovery { "rails" }
Autotest.add_discovery { "rspec2" }
8 changes: 8 additions & 0 deletions config/cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%
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"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
5 changes: 4 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ development:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
test: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
Expand All @@ -20,3 +20,6 @@ production:
database: db/production.sqlite3
pool: 5
timeout: 5000

cucumber:
<<: *test
6 changes: 6 additions & 0 deletions features/autocomplete.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Autocomplete
In order to do funky stuff
As a User
I want to have autocomplete!


100 changes: 100 additions & 0 deletions features/step_definitions/pickle_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# this file generated by script/generate pickle

# create a model
Given(/^#{capture_model} exists?(?: with #{capture_fields})?$/) do |name, fields|
create_model(name, fields)
end

# create n models
Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
count.to_i.times { create_model(plural_factory.singularize, fields) }
end

# create models from a table
Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
create_models_from_table(plural_factory, table)
end

# find a model
Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
find_model!(name, fields)
end

# not find a model
Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields|
find_model(name, fields).should be_nil
end

# find models with a table
Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
find_models_from_table(plural_factory, table).should_not be_any(&:nil?)
end

# find exactly n models
Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
find_models(plural_factory.singularize, fields).size.should == count.to_i
end

# assert equality of models
Then(/^#{capture_model} should be #{capture_model}$/) do |a, b|
model!(a).should == model!(b)
end

# assert model is in another model's has_many assoc
Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
model!(owner).send(association).should include(model!(target))
end

# assert model is not in another model's has_many assoc
Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
model!(owner).send(association).should_not include(model!(target))
end

# assert model is another model's has_one/belongs_to assoc
Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
model!(owner).send(association).should == model!(target)
end

# assert model is not another model's has_one/belongs_to assoc
Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
model!(owner).send(association).should_not == model!(target)
end

# assert model.predicate?
Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
model!(name).should send("have_#{predicate.gsub(' ', '_')}")
else
model!(name).should send("be_#{predicate.gsub(' ', '_')}")
end
end

# assert not model.predicate?
Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
model!(name).should_not send("have_#{predicate.gsub(' ', '_')}")
else
model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
end
end

# model.attribute.should eql(value)
# model.attribute.should_not eql(value)
Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
actual_value = model(name).send(attribute)
expectation = expectation.gsub(' ', '_')

case expected
when 'nil', 'true', 'false'
actual_value.send(expectation, send("be_#{expected}"))
when /^[+-]?[0-9_]+(\.\d+)?$/
actual_value.send(expectation, eql(expected.to_f))
else
actual_value.to_s.send(expectation, eql(eval(expected)))
end
end

# assert size of association
Then /^#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|
model!(name).send(association).size.should == size.to_i
end
Loading

0 comments on commit 44bbfe2

Please sign in to comment.