spec/spec_helper.rb in gitwakatime-0.2.2 vs spec/spec_helper.rb in gitwakatime-0.4.0

- old
+ new

@@ -4,11 +4,15 @@ # loaded once. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration ENV['thor_env'] = 'test' ENV['waka_log'] = 'false' +require 'codeclimate-test-reporter' +CodeClimate::TestReporter.start +require 'webmock/rspec' +WebMock.disable_net_connect!(allow: 'codeclimate.com') require 'gitwakatime' RSpec.configure do |config| config.run_all_when_everything_filtered = true config.filter_run :focus @@ -19,40 +23,22 @@ GitWakaTime::Commit.new.columns GitWakaTime::CommitedFile.new.columns GitWakaTime::Heartbeat.new.columns end - config.before(:each) do - GitWakaTime::Commit.truncate - GitWakaTime::CommitedFile.truncate - GitWakaTime::Heartbeat.truncate + config.around(:each) do |example| + DB.transaction(rollback: :always, auto_savepoint: true) { example.run } + end - expect( + config.before(:each) do + allow( GitWakaTime.config - ).to receive('user_name').and_return('Russell Osborne').at_least(:once) + ).to receive('user_name').and_return('Russell Osborne') end config.after(:all) do FileUtils.rm_r(File.dirname(@wdir)) end -end -require 'codeclimate-test-reporter' -CodeClimate::TestReporter.start -require 'webmock/rspec' - -WebMock.disable_net_connect!(allow: 'codeclimate.com') - -def capture(stream) - begin - stream = stream.to_s - eval "$#{stream} = StringIO.new" - yield - result = eval("$#{stream}").string - ensure - eval("$#{stream} = #{stream.upcase}") - end - - result end def set_file_paths @test_dir = File.join(File.dirname(__FILE__)) @wdir_dot = File.expand_path(File.join(@test_dir, 'dummy'))