improve integration test of cli scripts

This commit is contained in:
Reinier Balt 2013-09-20 21:18:33 +02:00
parent 4c73e260e3
commit daef1c440b
9 changed files with 152 additions and 42 deletions

View file

@ -56,7 +56,7 @@ group :test do
gem "database_cleaner"
gem "mocha", :require => false
gem "aruba", :require => false
gem "aruba", git: 'https://github.com/cucumber/aruba', :require => false # need 0.5.4 for piping files; 0.5.3 is latest
gem "simplecov"
gem "timecop", "~> 0.6.2"

View file

@ -1,3 +1,12 @@
GIT
remote: https://github.com/cucumber/aruba
revision: adbfc240d69254d7b525876b4c5bff6b721b7d65
specs:
aruba (0.5.3)
childprocess (>= 0.3.6)
cucumber (>= 1.1.1)
rspec-expectations (>= 2.7.0)
GIT
remote: https://github.com/rails/actionpack-xml_parser
revision: 246653ab3670f329176c1e77e6cd1a632466f06e
@ -37,10 +46,6 @@ GEM
acts_as_list (0.3.0)
activerecord (>= 3.0)
arel (4.0.0)
aruba (0.5.3)
childprocess (>= 0.3.6)
cucumber (>= 1.1.1)
rspec-expectations (>= 2.7.0)
atomic (1.1.14)
bcrypt-ruby (3.0.1)
builder (3.1.4)
@ -57,7 +62,7 @@ GEM
xpath (~> 2.0)
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
codeclimate-test-reporter (0.0.9)
codeclimate-test-reporter (0.0.11)
simplecov (>= 0.7.1, < 1.0.0)
coffee-rails (4.0.0)
coffee-script (>= 2.2.0)
@ -187,10 +192,10 @@ GEM
multi_json (~> 1.0, >= 1.0.2)
uniform_notifier (1.3.0)
websocket (1.0.7)
will_paginate (3.0.4)
will_paginate (3.0.5)
xpath (2.0.0)
nokogiri (~> 1.3)
yard (0.8.7.1)
yard (0.8.7.2)
PLATFORMS
ruby
@ -200,7 +205,7 @@ DEPENDENCIES
aasm
actionpack-xml_parser!
acts_as_list
aruba
aruba!
bcrypt-ruby (~> 3.0.0)
bullet
cache_digests

View file

@ -1,4 +1,4 @@
require 'time'
require 'active_support/time_with_zone'
module TracksCli

View file

@ -0,0 +1,36 @@
Feature: Add a todo to Tracks on console
In order to be able to add a todo from the command line
As a user who has installed Tracks with console access
I want to run the script to add a todo
These scenarios are tagged javascript so that there is a Tracks server running
to use from the command line script
Background:
Given the following user records
| login | password | is_admin |
| testuser | secret | false |
| admin | secret | true |
And I have logged in as "testuser" with password "secret"
And I have a context called "Context A"
And I have a project called "Project A"
@javascript @aruba
Scenario: Create a single todo
Given a console input that looks like
"""
a new todo
"""
When I execute the add-todo script
Then I should have 1 todo in project "Project A"
@javascript @aruba
Scenario: Create multiple todos
Given a console input that looks like
"""
todo 1
todo 2
"""
When I execute the add-todo script
Then I should have 2 todo in project "Project A"

View file

@ -1,4 +1,4 @@
Feature: Create project from template
Feature: Create project from template on console
In order to be able to create a project from a template
As a user who has installed Tracks with console access
I want to run the script to add projects and actions from a template
@ -21,7 +21,7 @@ Feature: Create project from template
My first project
.My first task in this project
"""
When I execute the script
When I execute the template script
Then I should have a project called "My first project"
And I should have 1 todo in project "My first project"
@ -33,5 +33,5 @@ Feature: Create project from template
.Todo
^Dependent
"""
When I execute the script
When I execute the template script
Then the successors of "Todo" should include "Dependent"

View file

@ -0,0 +1,59 @@
Given /^a template that looks like$/ do |template|
steps %{
Given a file named "template.txt" with:
"""
#{template}
"""
}
end
Given /^a console input that looks like$/ do |input|
steps %{
Given a file named "todo.txt" with:
"""
#{input}
"""
}
end
When /^I execute the template script$/ do
step "I cd to \"../..\""
context_id = @current_user.contexts.first.id
port = Capybara.current_session.server.port
# assumes there is a context with id=1
cli = "ruby doc/tracks_template_cli.rb -c #{context_id} -f tmp/aruba/template.txt"
set_env('GTD_LOGIN','testuser')
set_env('GTD_PASSWORD', 'secret')
set_env('GTD_TODOS_URL', "http://localhost:#{port}/todos.xml")
set_env('GTD_PROJECTS_URL', "http://localhost:#{port}/projects.xml")
set_env('GTD_CONTEXT_URL_PREFIX', "http://localhost:#{port}/contexts/")
set_env("GTD_CONTEXT_URL","http://localhost:#{port}/contexts.xml")
step "I run `#{cli}`"
end
When /^I execute the add-todo script$/ do
step "I cd to \"../..\""
# assumes there is a context and a project
context_id = @current_user.contexts.first.id
project_id = @current_user.projects.first.id
port = Capybara.current_session.server.port
cli = "ruby doc/tracks_cli_client.rb -c #{context_id} -p #{project_id}"
set_env('GTD_LOGIN','testuser')
set_env('GTD_PASSWORD', 'secret')
set_env('GTD_TODOS_URL', "http://localhost:#{port}/todos.xml")
step "I run `#{cli}` interactively"
step "I pipe in the file \"tmp/aruba/todo.txt\""
# it seems aruba does not wait for process to end with interactively run command, but
# continues anyway which will start cleaning up the database while the process is still running
# so wait 2 secs for the process to finish
sleep 2
end

View file

@ -1,27 +0,0 @@
Given /^a template that looks like$/ do |template|
steps %{
Given a file named "template.txt" with:
"""
#{template}
"""
}
end
When /^I execute the script$/ do
step "I cd to \"../..\""
context_id = @current_user.contexts.first.id
port = Capybara.current_session.server.port
# assumes there is a context with id=1
cli = "ruby doc/tracks_template_cli.rb -c #{context_id} -f tmp/aruba/template.txt"
set_env('GTD_LOGIN','testuser')
set_env('GTD_PASSWORD', 'secret')
set_env('GTD_TODOS_URL', "http://localhost:#{port}/todos.xml")
set_env('GTD_PROJECTS_URL', "http://localhost:#{port}/projects.xml")
set_env('GTD_CONTEXT_URL_PREFIX', "http://localhost:#{port}/contexts/")
set_env("GTD_CONTEXT_URL","http://localhost:#{port}/contexts.xml")
step "I run `#{cli}`"
end

View file

@ -0,0 +1,36 @@
require 'net/https'
require './test/minimal_test_helper'
require './doc/tracks_cli/tracks_api'
module TracksCli
class TracksApiTest < Test::Unit::TestCase
def test_https_detection
uri = URI.parse("https://tracks.example.com")
http = TracksCli::TracksAPI.new({}).get_http(uri)
assert http.use_ssl?, "ssl expected"
uri = URI.parse("http://tracks.example.com")
http = TracksCli::TracksAPI.new({}).get_http(uri)
assert !http.use_ssl?, "no ssl expected"
end
def test_context_uri
uri = TracksCli::TracksAPI.new({context_prefix: "c"}).context_uri_for(16)
assert_equal "c16.xml", uri.path
uri = TracksCli::TracksAPI.new({context_prefix: "c"}).context_uri_for(18)
assert_equal "c18.xml", uri.path
end
def test_static_uris_for_todo_and_project
uri = TracksCli::TracksAPI.new({projects_uri: "https//tracks.example.com/projects.xml"}).project_uri
assert_equal "https//tracks.example.com/projects.xml", uri.path
uri = TracksCli::TracksAPI.new({uri: "https//tracks.example.com/todos.xml"}).todo_uri
assert_equal "https//tracks.example.com/todos.xml", uri.path
end
end
end

View file

@ -1,9 +1,10 @@
require './test/minimal_test_helper'
require './doc/tracks_cli/tracks_xml_builder'
require 'active_support/time_with_zone'
module TracksCli
class TimeToCompleteTest < Test::Unit::TestCase
class TracksXmlBuilderTest < Test::Unit::TestCase
def test_all
todo = {
description: "test action",
@ -18,7 +19,7 @@ module TracksCli
xml = TracksCli::TracksXmlBuilder.new.build_todo_xml(todo)
expect = "<todo><description>test action</description>" +
"<project_id>1</project_id><show-from type=\"datetime\">2013-01-01T14:00:00Z</show-from>" +
"<project_id>1</project_id><show-from type=\"datetime\">#{Time.at(todo[:show_from]).xmlschema}</show-from>" +
"<notes>action notes</notes><tags><tag><name>one</name></tag><tag><name>two</name></tag></tags>" +
"<context><name>@home</name></context><predecessor_dependencies><predecessor>123</predecessor></predecessor_dependencies></todo>"