Skip to content

Commit

Permalink
Codecov.io test
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas committed Oct 16, 2016
1 parent 5bf4438 commit 7306712
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ gemspec
unless Gem.win_platform? || RUBY_PLATFORM == "java"
gem 'byebug', group: [:development, :test]
end

gem 'simplecov', require: false, group: :test

gem 'codecov', require: false, group: :test if ENV["CI"]
5 changes: 4 additions & 1 deletion Gemfile.norbnacl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ source 'https://rubygems.org'

ENV['NET_SSH_NO_RBNACL'] = 'true'
# Specify your gem's dependencies in mygem.gemspec
gemspec
gemspec

gem 'simplecov', require: false, group: :test
gem 'codecov', require: false, group: :test
4 changes: 2 additions & 2 deletions lib/net/ssh/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module Test
# If a block is given, yields the script for the test socket (#socket).
# Otherwise, simply returns the socket's script. See Net::SSH::Test::Script.
def story
yield socket.script if block_given?
Net::SSH::Test::Extensions::IO.with_test_extension { yield socket.script if block_given? }
return socket.script
end

Expand Down Expand Up @@ -81,7 +81,7 @@ def transport(options={})
# the block passed to this assertion.
def assert_scripted
raise "there is no script to be processed" if socket.script.events.empty?
yield
Net::SSH::Test::Extensions::IO.with_test_extension { yield }
assert socket.script.events.empty?, "there should not be any remaining scripted events, but there are still #{socket.script.events.length} pending"
end
end
Expand Down
17 changes: 17 additions & 0 deletions lib/net/ssh/test/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ def self.included(base) #:nodoc:
base.extend(ClassMethods)
end

@extension_enabled = false

def self.with_test_extension(&block)
orig_value = @extension_enabled
@extension_enabled = true
begin
yield
ensure
@extension_enabled = orig_value
end
end

def self.extension_enabled?
@extension_enabled
end

module ClassMethods
def self.extended(obj) #:nodoc:
class <<obj
Expand All @@ -125,6 +141,7 @@ class <<obj
# writers, and errors arrays are either nil, or contain only objects
# that mix in Net::SSH::Test::Extensions::BufferedIo.
def select_for_test(readers=nil, writers=nil, errors=nil, wait=nil)
return select_for_real(readers, writers, errors, wait) unless Net::SSH::Test::Extensions::IO.extension_enabled?
ready_readers = Array(readers).select { |r| r.select_for_read? }
ready_writers = Array(writers).select { |r| r.select_for_write? }
ready_errors = Array(errors).select { |r| r.select_for_error? }
Expand Down
8 changes: 8 additions & 0 deletions test/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
require 'net/ssh/transport/session'
require 'ostruct'

if ENV["CI"]
require 'simplecov'
SimpleCov.start

require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
end

# clear the default files out so that tests don't get confused by existing
# SSH config files.
$_original_config_default_files = Net::SSH::Config.default_files.dup # rubocop:disable Style/GlobalVars
Expand Down

0 comments on commit 7306712

Please sign in to comment.