From e60275b8490d74bdd711f92965498468343414c5 Mon Sep 17 00:00:00 2001 From: tk Date: Tue, 18 Aug 2015 23:56:14 -0500 Subject: [PATCH] Call TogglV8SpecHelper.setUp() before test suite to prepare known state. --- Rakefile | 2 +- spec/lib/togglv8_users_spec.rb | 1 - spec/spec_helper.rb | 9 ++++++ spec/togglv8_spec_helper.rb | 54 ++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 spec/togglv8_spec_helper.rb diff --git a/Rakefile b/Rakefile index f48924b7a..c65c9757a 100644 --- a/Rakefile +++ b/Rakefile @@ -5,4 +5,4 @@ task :clean do FileUtils.remove_dir('coverage', force=true) FileUtils.remove_dir('doc', force=true) FileUtils.remove_dir('pkg', force=true) -end \ No newline at end of file +end diff --git a/spec/lib/togglv8_users_spec.rb b/spec/lib/togglv8_users_spec.rb index 33c722d88..c43a63060 100644 --- a/spec/lib/togglv8_users_spec.rb +++ b/spec/lib/togglv8_users_spec.rb @@ -11,7 +11,6 @@ expect(@user).to_not be_nil expect(@user['id']).to eq 1820939 expect(@user['fullname']).to eq 'togglv8' - expect(@user['default_wid']).to eq 1060392 expect(@user['image_url']).to eq 'https://assets.toggl.com/avatars/a5d106126b6bed8df283e708af0828ee.png' expect(@user['timezone']).to eq 'Etc/UTC' expect(@user['workspaces'].length).to eq 1 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5f7374b53..b90a5d40b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,11 @@ add_filter '/pkg/' end +# NOTE: SimpleCov.start must be issued before any application code is required! +# ----------------------------------------------------------------------------- + +require_relative 'togglv8_spec_helper' + # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause this @@ -48,6 +53,10 @@ mocks.verify_partial_doubles = true end + config.before(:suite) do + TogglV8SpecHelper.setUp() + end + # The settings below are suggested to provide a good initial experience # with RSpec, but feel free to customize to your heart's content. =begin diff --git a/spec/togglv8_spec_helper.rb b/spec/togglv8_spec_helper.rb new file mode 100644 index 000000000..79772a2e3 --- /dev/null +++ b/spec/togglv8_spec_helper.rb @@ -0,0 +1,54 @@ +require_relative '../lib/togglv8' +require 'logger' + +class TogglV8SpecHelper + @logger = Logger.new(STDOUT) + + def self.setUp() + toggl = Toggl::V8.new(Testing::TEST_API_TOKEN) + user = toggl.me(all=true) + default_workspace_id = user['default_wid'] + + clients = toggl.my_clients(user) + unless clients.nil? + client_ids ||= clients.map { |c| c['id'] } + client_ids.each do |c_id| + toggl.delete_client(c_id) + end + end + + projects = toggl.my_projects(user) + unless projects.nil? + project_ids ||= projects.map { |p| p['id'] } + project_ids.each do |p_id| + toggl.delete_project(p_id) + end + end + + tags = toggl.my_tags(user) + unless tags.nil? + tag_ids ||= tags.map { |t| t['id'] } + tag_ids.each do |t_id| + toggl.delete_tag(t_id) + end + end + + time_entrys = toggl.my_time_entries(user) + unless time_entrys.nil? + time_entry_ids ||= time_entrys.map { |t| t['id'] } + time_entry_ids.each do |t_id| + toggl.delete_time_entry(t_id) + end + end + + workspaces = toggl.my_workspaces(user) + unless workspaces.nil? + workspace_ids ||= workspaces.map { |w| w['id'] } + workspace_ids.delete(default_workspace_id) + workspace_ids.each do |w_id| + @logger.debug(w_id) + toggl.leave_workspace(w_id) + end + end + end +end \ No newline at end of file