diff --git a/Gemfile b/Gemfile index d8929761..2dc4858e 100644 --- a/Gemfile +++ b/Gemfile @@ -54,6 +54,7 @@ group :test do gem "selenium-webdriver" # Note that > 2.14 has problems: https://code.google.com/p/selenium/issues/detail?id=3075 gem "database_cleaner", ">=0.5.0" gem "cucumber-rails", "~>0.3.2" + gem "aruba" # uncomment to use the webkit option. This depends on Qt to be installed #gem "capybara-webkit" diff --git a/Gemfile.lock b/Gemfile.lock index 102337ca..b8410960 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,6 +16,7 @@ GEM activesupport (= 2.3.14) activesupport (2.3.14) acts_as_list (0.1.4) + aruba (0.2.2) bcrypt-ruby (2.1.4) builder (3.0.0) capybara (1.1.2) @@ -132,6 +133,7 @@ DEPENDENCIES ZenTest (>= 4.0.0) aasm (~> 2.2.0) acts_as_list (~> 0.1.4) + aruba bcrypt-ruby (~> 2.1.4) capybara (>= 0.3.5) cucumber-rails (~> 0.3.2) diff --git a/features/make_project_from_template.feature b/features/make_project_from_template.feature new file mode 100644 index 00000000..acd0a982 --- /dev/null +++ b/features/make_project_from_template.feature @@ -0,0 +1,37 @@ +Feature: Create project from template + In order to be able to create a project from a template + As a user this installed Tracks with console access + I want to run the script to add projects and actions from a template + + These scenario's need selenium 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" + + @javascript + Scenario: Create a project with one task + Given a template that looks like + """ + My first project + .My first task in this project + """ + When I execute the script + Then I should have a project called "My first project" + And I should have 1 todo in project "My first project" + + @javascript + Scenario: Create a project with dependent tasks + Given a template that looks like + """ + My first project + .Todo + ^Dependent + """ + When I execute the script + Then the successors of "Todo" should include "Dependent" diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index 9f697ce5..caafbf9b 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -130,29 +130,6 @@ When /^I edit the default context to "([^"]*)"$/ do |default_context| end end -Then /^I should (see|not see) empty message for (todos|deferred todos|completed todos) of project/ do |visible, state| - case state - when "todos" - css = "div#p#{@project.id}empty-nd" - when "deferred todos" - css = "div#tickler-empty-nd" - when "completed todos" - css = "div#empty-d" - else - css = "wrong state" - end - - elem = find(css) - elem.should_not be_nil - elem.send(visible=="see" ? "should" : "should_not", be_visible) -end - -Then /^I edit the default tags to "([^"]*)"$/ do |default_tags| - edit_project(@project) do - fill_in "project[default_tags]", :with => default_tags - end -end - When /^I edit the project name of "([^"]*)" to "([^"]*)"$/ do |project_current_name, project_new_name| @project = @current_user.projects.find_by_name(project_current_name) @project.should_not be_nil @@ -175,12 +152,6 @@ When /^I click to edit the project name in place$/ do page.find("div#project_name").click end -Then /^I should be able to change the project name in place$/ do - #Note that this is not changing the project name - page.should have_css("div#project_name>form>input") - page.find("div#project_name > form > button[type=cancel]").click -end - When /^I edit the project settings$/ do @project.should_not be_nil @@ -188,10 +159,6 @@ When /^I edit the project settings$/ do page.should have_xpath("//div[@id='edit_project_#{@project.id}']/form//button[@id='submit_project_#{@project.id}']") end -Then /^I should not be able to change the project name in place$/ do - step "I click to edit the project name in place" - page.should_not have_xpath("//div[@id='project_name']/form/input") -end When /^I close the project settings$/ do @project.should_not be_nil @@ -229,6 +196,40 @@ When /^I cancel adding a note to the project$/ do click_link "neg_edit_form_note" end +Then /^I should (see|not see) empty message for (todos|deferred todos|completed todos) of project/ do |visible, state| + case state + when "todos" + css = "div#p#{@project.id}empty-nd" + when "deferred todos" + css = "div#tickler-empty-nd" + when "completed todos" + css = "div#empty-d" + else + css = "wrong state" + end + + elem = find(css) + elem.should_not be_nil + elem.send(visible=="see" ? "should" : "should_not", be_visible) +end + +Then /^I edit the default tags to "([^"]*)"$/ do |default_tags| + edit_project(@project) do + fill_in "project[default_tags]", :with => default_tags + end +end + +Then /^I should be able to change the project name in place$/ do + #Note that this is not changing the project name + page.should have_css("div#project_name>form>input") + page.find("div#project_name > form > button[type=cancel]").click +end + +Then /^I should not be able to change the project name in place$/ do + step "I click to edit the project name in place" + page.should_not have_xpath("//div[@id='project_name']/form/input") +end + Then /^the form for adding a note should not be visible$/ do page.should_not have_css("edit_form_note") end @@ -279,4 +280,15 @@ Then /^I should (see|not see) the default project settings$/ do |visible| else elem.should_not be_visible end -end \ No newline at end of file +end + +Then /^I should have a project called "([^"]*)"$/ do |project_name| + project = @current_user.projects.find_by_name(project_name) + project.should_not be_nil +end + +Then /^I should have (\d+) todo in project "([^"]*)"$/ do |todo_count, project_name| + project = @current_user.projects.find_by_name(project_name) + project.should_not be_nil + project.todos.count.should == todo_count.to_i +end diff --git a/features/step_definitions/template_steps.rb b/features/step_definitions/template_steps.rb new file mode 100644 index 00000000..2ff2f9f7 --- /dev/null +++ b/features/step_definitions/template_steps.rb @@ -0,0 +1,29 @@ +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 + + # assumes there is a context with id=1 + cli = "ruby doc/tracks_template_cli.rb -c #{context_id} -f tmp/aruba/template.txt" + login = "GTD_LOGIN=testuser" + pass = "GTD_PASSWORD=secret" + port = Capybara.current_session.driver.rack_server.port + gtd_todos_url = "GTD_TODOS_URL=http://localhost:#{port}/todos.xml" + gtd_projects_url = "GTD_PROJECTS_URL=http://localhost:#{port}/projects.xml" + gtd_context_url_prefix = "GTD_CONTEXT_URL_PREFIX=http://localhost:#{port}/contexts/" + gtd_context_url = "GTD_CONTEXT_URL=http://localhost:#{port}/contexts.xml" + + command = "#{gtd_todos_url} #{gtd_projects_url} #{gtd_context_url_prefix} #{gtd_context_url} #{login} #{pass} #{cli}" + + step "I run \"#{command}\"" + # puts "output = #{combined_output}" +end \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index c71266f5..b885cf21 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -12,6 +12,7 @@ require 'cucumber/rails/rspec' require 'cucumber/rails/world' require 'cucumber/rails/active_record' require 'cucumber/web/tableish' +require 'aruba/cucumber' require 'capybara/rails' require 'capybara/cucumber' diff --git a/features/support/selenium.rb b/features/support/selenium.rb deleted file mode 100644 index 4f6f8f0a..00000000 --- a/features/support/selenium.rb +++ /dev/null @@ -1,19 +0,0 @@ -if ENV["RAILS_ENV"] == "selenium" - puts "Configuring to use Selenium with Webrat for Cucumber stories" - Webrat.configure do |config| - config.mode = :selenium - - config.application_environment = :selenium - # use only if you run a separate rails test server instance and do not - # want webrat to start one for you - # config.application_port = 3001 - - config.selenium_browser_startup_timeout = 30 - # use only if you run a separate selenium server instance and do not - # want webrat to start one for you - # config.selenium_server_address = "localhost" - # config.selenium_server_port = "4444" - end - - Cucumber::Rails::World.use_transactional_fixtures = false -end