Skip to content

Commit

Permalink
Call TogglV8SpecHelper.setUp() before test suite to prepare known state.
Browse files Browse the repository at this point in the history
  • Loading branch information
tk committed Aug 19, 2015
1 parent fa1d69b commit e60275b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
1 change: 0 additions & 1 deletion spec/lib/togglv8_users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions spec/togglv8_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e60275b

Please sign in to comment.