spec/helper.rb in tomatoharvest-0.0.1 vs spec/helper.rb in tomatoharvest-0.1.0

- old
+ new

@@ -3,79 +3,63 @@ require 'tomatoharvest' require 'webmock/rspec' require 'minitest/unit' +require 'support/file_helpers' +require 'support/harvest_helpers' + WebMock.disable_net_connect!(allow_localhost: true) RSpec.configure do |c| c.include MiniTest::Assertions + c.include FileHelpers + c.include HarvestHelpers # # Speed up the timer # - c.before :all do - class TomatoHarvest::Timer - def sleep(time) - super(time/100000) - end - end + c.before :each do + const = 'TomatoHarvest::Timer::SLEEP_LENGTH' + stub_const(const, 1/100000) end # # Stub HTTP requests # c.before do - body = { - projects: [ { - name: 'Pomdoro', - id: 1, - tasks: [ - { - name: 'Ruby Development', - id: 1 - } - ] - } ], - day_entries: [] - } - - stub_request(:get, /https:\/\/user:password@domain.harvestapp.com\/daily\/.*/). - with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Harvestable/2.0.0'}). - to_return(:status => 200, :body => body.to_json, :headers => {}) - - stub_request(:post, "https://user:password@domain.harvestapp.com/daily/add"). - with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Harvestable/2.0.0'}). - to_return(:status => 200, :body => "", :headers => {}) + stub_harvest end # # Don't daemonize for tests # Dont notify the terminal # c.before do - Daemons.stub(daemonize: false) - TerminalNotifier.stub(notify: true) - TomatoHarvest::Tmux.any_instance.stub(update: true) + allow(Daemons).to receive(:daemonize) { false } + allow(TerminalNotifier).to receive(:notify) { true } + allow_any_instance_of(TomatoHarvest::Tmux).to receive(:update) { true } end + # Stub Home dir + c.before(:each) do + stub_const('TomatoHarvest::Config::HOME_DIR', 'spec/') + end + # - # Cleanup .toma and .tomaconfig + # Cleanup .toma/ # [ - ["TomatoHarvest::Config::CONFIG_PATH", File.expand_path('spec/.tomaconfig')], - ["TomatoHarvest::Config::LOCAL_CONFIG_PATH", File.expand_path('.tomaconfig')], - ["TomatoHarvest::List::PATH", File.expand_path('spec/.toma')] - ].each do |tuple| - path = tuple[1] - + ["TomatoHarvest::Config::GLOBAL_DIR", File.expand_path('spec/.toma/')], + ["TomatoHarvest::Config::LOCAL_DIR", File.expand_path('.toma/')] + ].each do |const, path| c.before :each do - stub_const(tuple[0], path) - File.delete(path) if File.exists?(path) + stub_const(const, path) + FileUtils.rm_rf(path) if File.directory?(path) end c.after :each do - File.delete(path) if File.exists?(path) + FileUtils.rm_rf(path) if File.directory?(path) end end end