Skip to content
Browse files

Implement the feature steps and the app to make them pass.

  • Loading branch information...
1 parent b1646a3 commit bbc8fb15e1fdca3939d85bd595fd90a1649b263d @jcoglan committed
Showing with 80 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +11 −0 Gemfile
  3. +18 −0 app.rb
  4. +30 −0 features/step_definitions/app_steps.rb
  5. +10 −0 features/support/env.rb
  6. +10 −0 views/signup.erb
View
1 .gitignore
@@ -0,0 +1 @@
+Gemfile.lock
View
11 Gemfile
@@ -0,0 +1,11 @@
+source "http://rubygems.org"
+
+gem "sinatra"
+
+group :development do
+ gem "capybara"
+ gem "cucumber"
+ gem "rack-test"
+ gem "rspec"
+end
+
View
18 app.rb
@@ -0,0 +1,18 @@
+require 'sinatra'
+
+get '/signup' do
+ erb :signup
+end
+
+post '/accounts/create' do
+ if params[:username] == 'Wizard'
+ 'Your argument is invalid'
+ elsif params[:username] != 'Harry'
+ 'Your name is invalid'
+ elsif params[:email] !~ /@/
+ 'Your email is invalid'
+ else
+ 'You are a wizard, Harry!'
+ end
+end
+
View
30 features/step_definitions/app_steps.rb
@@ -0,0 +1,30 @@
+Given /^I visit the sign\-up form$/ do
+ visit '/signup'
+end
+
+When /^I enter an invalid name$/ do
+ fill_in 'Username', :with => 'Hagrid'
+ click_button 'Sign up'
+end
+
+When /^I enter an invalid email address$/ do
+ fill_in 'Username', :with => 'Harry'
+ fill_in 'Email', :with => 'wizard [at] hogwarts.com'
+ click_button 'Sign up'
+end
+
+When /^I use an invalid argument$/ do
+ fill_in 'Username', :with => 'Wizard'
+ click_button 'Sign up'
+end
+
+When /^I enter valid sign\-up data$/ do
+ fill_in 'Username', :with => 'Harry'
+ fill_in 'Email', :with => 'wizard@hogwarts.com'
+ click_button 'Sign up'
+end
+
+Then /^I should see "([^"]*)"$/ do |text|
+ page.should have_content(text)
+end
+
View
10 features/support/env.rb
@@ -0,0 +1,10 @@
+require 'bundler/setup'
+require File.expand_path('../../../app', __FILE__)
+
+require 'rspec'
+require 'capybara/dsl'
+World Capybara::DSL
+
+Capybara.current_driver = :rack_test
+Capybara.app = Sinatra::Application
+
View
10 views/signup.erb
@@ -0,0 +1,10 @@
+<form method="post" action="/accounts/create">
+ <label for="username">Username</label>
+ <input type="text" id="username" name="username">
+
+ <label for="email">Email</label>
+ <input type="text" id="email" name="email">
+
+ <input type="submit" value="Sign up">
+</form>
+

0 comments on commit bbc8fb1

Please sign in to comment.
Something went wrong with that request. Please try again.