Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add cucumbers to describe basic features

  • Loading branch information...
commit 008b8bf94bb4dfda6a57bc24cb6cea67cf9423f8 1 parent 6078bbe
@chischaschos authored
View
1  .gitignore
@@ -1,3 +1,4 @@
+capybara*
.bundle
log/*
db/*
View
5 Gemfile
@@ -15,13 +15,14 @@ group 'development' do
end
group :development, :test do
- gem 'capybara-webkit'
- gem 'cucumber'
gem 'debugger'
end
group :test do
+ gem 'capybara-webkit'
+ gem 'cucumber'
gem 'database_cleaner'
gem 'json_spec'
+ gem 'launchy'
gem 'rspec'
end
View
3  Gemfile.lock
@@ -93,6 +93,8 @@ GEM
json_spec (1.1.1)
multi_json (~> 1.0)
rspec (~> 2.0)
+ launchy (2.4.2)
+ addressable (~> 2.3)
mime-types (2.1)
mini_portile (0.5.2)
multi_json (1.8.4)
@@ -146,6 +148,7 @@ DEPENDENCIES
ejs
haml
json_spec
+ launchy
rack-contrib
rack-cors
rspec
View
13 config.ru
@@ -3,18 +3,9 @@ $LOAD_PATH << File.expand_path('lib')
require 'todo'
map '/assets' do
- environment = Sprockets::Environment.new Todo::Application.root
- environment.append_path 'vendor/js'
- environment.append_path 'assets/js'
- run environment
-end
-
-use Rack::Cors do
- allow do
- origins '*'
- resource '*', :headers => :any, :methods => [:get, :post, :put, :delete]
- end
+ run Todo::Assets.environment
end
use Todo::Api
+
run Todo::Frontend
View
59 features/a_user_can_create_a_todo_list.feature
@@ -1,35 +1,44 @@
-Feature: A user can create a todo list
+Feature: A user can create a TODO list
As an anonymous user
- I want to create a todo list
- So I can manage my todo items
-
- Scenario: The server is down and the user can not sign up/ sign in
-
- Scenario: The user fills in an empty email and/or password and can not sign in
-
- Scenario: The user fills in an empty email and/or password and can not sign up
-
- Scenario: The user signs in
+ I want to create a TODO list
+ So I can manage my TODO items
Scenario: The user signs up
-
- Scenario: The user signs out
-
- Scenario: The user creates a todo list
Given I go to the home page
- And I create a list
- And I add the "buy milk" item
+ When I submit the sign up form
+ Then I should see the TODO dashboard
+
+ Scenario: The user creates a TODO list
+ Given I already have an account
+ And I go to the sign in page
+ When I submit the sign in form
+ Then I should see the TODO dashboard
+ When I add the "buy milk" item
And I add the "buy beer" item
And I add the "get new clothes" item
- When I go to manage my list
- Then I can delete the "buy milk item"
- And I can add the "buy beans" item
- And I can edit the "buy beer" to "buy a lot of beer"
-
- Scenario: The API is accessed
-
- Scenario: I can mark an item as completed
+ Then I should only see these items:
+ |description|
+ |buy milk|
+ |buy beer|
+ |get new clothes|
+ And I can delete the "buy milk"
+ And I add the "buy beans" item
+ And I edit the "buy beer" to "buy a lot of beer"
+ And I mark as completed "buy a lot of beer"
+ Then I should only see these items:
+ |description|
+ |buy beans|
+ |buy a lot of beer|
+ |get new clothes|
Scenario: I can sort items by due date
Scenario: I can sort items by priority
+
+ Scenario: The server is down and the user can not sign up/ sign in
+
+ Scenario: The user fills in an empty email and/or password and can not sign in
+
+ Scenario: The user fills in an empty email and/or password and can not sign up
+
+
View
64 features/step_definitions/steps.rb
@@ -0,0 +1,64 @@
+Given(/^I go to the home page$/) do
+ visit '/'
+end
+
+Given(/^I go to the sign in page$/) do
+ visit '/'
+ click_link 'Already have an account?'
+end
+
+When(/^I submit the sign up form$/) do
+ fill_in :email, with: 'test@test.com'
+ fill_in :password, with: '123test123'
+ click_button 'Sign Up'
+end
+
+When(/^I submit the sign in form$/) do
+ fill_in :email, with: 'test@test.com'
+ fill_in :password, with: '123test123'
+ click_button 'Sign In'
+end
+
+Then(/^I should see the TODO dashboard$/) do
+ expect(page).to have_content("sign out")
+end
+
+Given(/^I already have an account$/) do
+ Todo::Models::User.create email: 'test@test.com', password: '123test123'
+end
+
+When(/^I add the "(.*?)" item$/) do |description|
+ click_link 'add'
+ fill_in :description, with: description
+ click_button 'Create'
+end
+
+Then(/^I should only see these items:$/) do |table|
+ step 'I should see the TODO dashboard'
+ descriptions = table.rows.flatten
+
+ doc = Nokogiri::HTML(page.body)
+ expect(doc.xpath('count(//tbody/tr)')).to eq descriptions.count
+ descriptions.each do |description|
+ expect(doc.xpath("//td[contains(text(), '#{description}')]")).not_to be_empty
+ end
+end
+
+Then(/^I can delete the "(.*?)"$/) do |description|
+ remove_link = find :xpath, "//tr[td//text()[contains(., '#{description}')]]/td[last()]/a[text() = 'remove']"
+ remove_link.click
+end
+
+Then(/^I edit the "(.*?)" to "(.*?)"$/) do |from_description, to_description|
+ edit_link = find :xpath, "//tr[td//text()[contains(., '#{from_description}')]]/td[last()]/a[text() = 'edit']"
+ edit_link.click
+ fill_in :description, with: to_description
+ click_button 'Save'
+end
+
+Then(/^I mark as completed "(.*?)"$/) do |description|
+ edit_link = find :xpath, "//tr[td//text()[contains(., '#{description}')]]/td[last()]/a[text() = 'edit']"
+ edit_link.click
+ check :completed
+ click_button 'Save'
+end
View
52 features/support/env.rb
@@ -0,0 +1,52 @@
+$LOAD_PATH << File.expand_path('lib')
+
+ENV['RACK_ENV'] = 'test'
+
+require 'debugger'
+require 'todo'
+require 'database_cleaner'
+require 'database_cleaner/cucumber'
+require 'capybara/cucumber'
+require 'capybara-webkit'
+require 'launchy'
+require 'rspec/matchers'
+require 'nokogiri'
+
+Capybara.configure do |config|
+ config.default_driver = :webkit
+ config.javascript_driver = :webkit
+ config.server_port = 1111
+end
+
+DatabaseCleaner[:data_mapper].strategy = :truncation
+
+Before do |scenario, block|
+ DatabaseCleaner.clean
+end
+
+#Before do
+#@dummy_app_pid = fork do
+#Todo::Frontend.use Todo::Api
+#exec Rack::Handler::WEBrick.run Todo::Frontend, {
+#Port: 1111,
+#BindAddress: 'localhost',
+#Logger: Todo::Frontend.logger,
+#AccessLog: [
+##[Rails.logger, WEBrick::AccessLog::COMMON_LOG_FORMAT]
+#]
+#}
+#end
+#end
+
+#After do
+#Process.kill 'KILL', @dummy_app_pid
+#end
+
+
+Capybara.app = Rack::Builder.new do
+ map '/assets' do
+ run Todo::Assets.environment
+ end
+ use Todo::Api
+ run Todo::Frontend
+end
View
1  lib/todo.rb
@@ -10,4 +10,5 @@ module Todo
autoload :Services, 'todo/services'
autoload :Middlewares, 'todo/middlewares'
autoload :MyLogger, 'todo/my_logger'
+ autoload :Assets, 'todo/assets'
end
View
7 lib/todo/api.rb
@@ -5,6 +5,13 @@ class Api < Application
use Rack::PostBodyContentTypeParser
+ use Rack::Cors do
+ allow do
+ origins '*'
+ resource '*', :headers => :any, :methods => [:get, :post, :put, :delete]
+ end
+ end
+
before '/api/*' do
content_type :json
end
View
10 lib/todo/assets.rb
@@ -0,0 +1,10 @@
+module Todo
+ module Assets
+ def self.environment
+ environment = Sprockets::Environment.new Todo::Application.root
+ environment.append_path 'vendor/js'
+ environment.append_path 'assets/js'
+ environment
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.