Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Sep 11, 2011
2 parents 9e51127 + 0f294ab commit 0b9b531
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -183,15 +183,15 @@ DEPENDENCIES
cucumber-rails! cucumber-rails!
database_cleaner (>= 0.6.7) database_cleaner (>= 0.6.7)
factory_girl (>= 2.1.0) factory_girl (>= 2.1.0)
jquery-rails (>= 1.0.12) jquery-rails (>= 1.0.14)
mongoid (>= 2.2.0) mongoid (>= 2.2.0)
rails (>= 3.1.0) rails (>= 3.1.0)
rake (>= 0.9.2) rake (>= 0.9.2)
rdiscount (= 1.6.8) rdiscount (= 1.6.8)
rspec (>= 2.6.0) rspec (>= 2.6.0)
rspec-rails (>= 2.6.1) rspec-rails (>= 2.6.1)
sass (>= 3.1.3) sass (>= 3.1.7)
sqlite3 (>= 1.3.4) sqlite3 (>= 1.3.4)
turn (>= 0.8.2) turn (>= 0.8.2)
uglifier (>= 1.0.0) uglifier (>= 1.0.3)
yard (= 0.7.2) yard (= 0.7.2)
12 changes: 6 additions & 6 deletions cucumber-rails.gemspec
Expand Up @@ -10,9 +10,9 @@ Gem::Specification.new do |s|
s.email = 'cukes@googlegroups.com' s.email = 'cukes@googlegroups.com'
s.homepage = "http://cukes.info" s.homepage = "http://cukes.info"


s.add_dependency('cucumber', '~> 1.0.4') s.add_runtime_dependency('cucumber', '~> 1.0.4')
s.add_dependency('nokogiri', '>= 1.5.0') s.add_runtime_dependency('nokogiri', '>= 1.5.0')
s.add_dependency('capybara', '>= 1.1.1') s.add_runtime_dependency('capybara', '>= 1.1.1')
s.add_development_dependency('rails', '>= 3.1.0') s.add_development_dependency('rails', '>= 3.1.0')
s.add_development_dependency('rake', '>= 0.9.2') s.add_development_dependency('rake', '>= 0.9.2')
s.add_development_dependency('bundler', '>= 1.0.18') s.add_development_dependency('bundler', '>= 1.0.18')
Expand All @@ -27,10 +27,10 @@ Gem::Specification.new do |s|


# Various Stuff that Rails 3.1 puts inside apps. # Various Stuff that Rails 3.1 puts inside apps.
s.add_development_dependency('turn', '>= 0.8.2') s.add_development_dependency('turn', '>= 0.8.2')
s.add_development_dependency('sass', '>= 3.1.3') s.add_development_dependency('sass', '>= 3.1.7')
s.add_development_dependency('coffee-script', '>= 2.2.0') s.add_development_dependency('coffee-script', '>= 2.2.0')
s.add_development_dependency('uglifier', '>= 1.0.0') s.add_development_dependency('uglifier', '>= 1.0.3')
s.add_development_dependency('jquery-rails', '>= 1.0.12') s.add_development_dependency('jquery-rails', '>= 1.0.14')


# For Documentation: # For Documentation:
s.add_development_dependency('yard', '= 0.7.2') s.add_development_dependency('yard', '= 0.7.2')
Expand Down
70 changes: 70 additions & 0 deletions features/field_with_errors.feature
@@ -0,0 +1,70 @@
Feature: Detecting a field has errors on it

Scenario: A form with some fields with errors
Given I have created a new Rails 3 app "enemies" with cucumber-rails support
And I successfully run `rails generate scaffold enemy name:string nickname:string`
And I write to "app/models/enemy.rb" with:
"""
class Enemy < ActiveRecord::Base
validates_presence_of :name
end
"""
And I write to "features/f.feature" with:
"""
Feature: Enemy form
Scenario: Making an enemy
Given I am on the new enemy page
And I press "Create Enemy"
Then the "Name" field should have the error "can't be blank"
And the "Nickname" field should have no error
"""
When I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then it should pass with:
"""
1 scenario (1 passed)
4 steps (4 passed)
"""

Scenario: A formtastic form with some fields with errors
Given I have created a new Rails 3 app "enemies" with cucumber-rails support
And I append to "Gemfile" with:
"""
gem "formtastic"
"""
And I successfully run `bundle`
And I successfully run `rails generate scaffold enemy name:string nickname:string`
And I write to "app/models/enemy.rb" with:
"""
class Enemy < ActiveRecord::Base
validates_presence_of :name
end
"""
And I write to "features/f.feature" with:
"""
Feature: Enemy form
Scenario: Making an enemy
Given I am on the new enemy page
And I press "Create Enemy"
Then the "Name" field should have the error "can't be blank"
And the "Nickname" field should have no error
"""
And I write to "app/views/enemies/new.html.erb" with:
"""
<%= semantic_form_for(@enemy) do |form| %>
<%= form.inputs do %>
<%= form.input :name %>
<%= form.input :nickname %>
<% end %>
<%= form.buttons do %>
<%= form.commit_button %>
<% end %>
<% end %>
"""
When I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then it should pass with:
"""
1 scenario (1 passed)
4 steps (4 passed)
"""
Expand Up @@ -143,6 +143,49 @@ Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |f
end end
end end


Then /^the "([^"]*)" field should have the error "([^"]*)"$/ do |field, error_message|
element = find_field(field)
classes = element.find(:xpath, '..')[:class].split(' ')

form_for_input = element.find(:xpath, 'ancestor::form[1]')
using_formtastic = form_for_input[:class].include?('formtastic')
error_class = using_formtastic ? 'error' : 'field_with_errors'

if classes.respond_to? :should
classes.should include(error_class)
else
assert classes.include?(error_class)
end

if page.respond_to?(:should)
if using_formtastic
error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]')
error_paragraph.should have_content(error_message)
else
page.should have_content("#{field.titlecase} #{error_message}")
end
else
if using_formtastic
error_paragraph = element.find(:xpath, '../*[@class="inline-errors"][1]')
assert error_paragraph.has_content?(error_message)
else
assert page.has_content?("#{field.titlecase} #{error_message}")
end
end
end

Then /^the "([^"]*)" field should have no error$/ do |field|
element = find_field(field)
classes = element.find(:xpath, '..')[:class].split(' ')
if classes.respond_to? :should
classes.should_not include('field_with_errors')
classes.should_not include('error')
else
assert !classes.include?('field_with_errors')
assert !classes.include?('error')
end
end

Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent| Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
with_scope(parent) do with_scope(parent) do
field_checked = find_field(label)['checked'] field_checked = find_field(label)['checked']
Expand Down

0 comments on commit 0b9b531

Please sign in to comment.