croaky-rspec 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 96cc773958ccf61a6ec8d239e0bf8b8842cf3e4c4298304984f5ef5a1da42238
4
+ data.tar.gz: d53e758996c2e3341e75c1d7d6773e6d074bc8801063081b6d9b1537d81dd197
5
+ SHA512:
6
+ metadata.gz: 7a3f5f511c6cbb5d9ab79c1ffdb1544d8bb9db700d34454b9967ad3baea2b6990c0036da47d3a212fa9186a9608f02b69cb2e0af75e05a468e6ebe243db2ed3a
7
+ data.tar.gz: 32c5aaea9381c390cbcd9e60305f250a12fec543d34735bf964e55967c8abce18c4bc4682f390b04bda88cf23b924bb1abd27a4aef80806ca92f2d430d5857ba
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Publishes a gem to rubygems.org
4
+
5
+ GEM_VERSION=$(ruby -I ./lib -r croaky/version -e 'puts Croaky::VERSION')
6
+
7
+ git tag --list | grep "$GEM_VERSION"
8
+
9
+ if [ $? -ne 0 ]; then
10
+ echo "Build and release new Gem version..."
11
+ mkdir -p "$HOME"/.gem
12
+ touch "$HOME"/.gem/credentials
13
+ chmod 0600 "$HOME"/.gem/credentials
14
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
15
+ git config --global credential.helper store
16
+ echo "https://${GITHUB_ACCESS_TOKEN}:x-oauth-basic@github.com" > ~/.git-credentials
17
+ git checkout master
18
+ git config user.email "sayantam@gmail.com"
19
+ git config user.name "Sayantam Dey"
20
+ bundle exec rake release
21
+ fi
@@ -0,0 +1,12 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ insert_final_newline = true
6
+ trim_trailing_whitespace = true
7
+
8
+
9
+ [*.{rb,yml}]
10
+ indent_size = 2
11
+ indent_style = space
12
+ tab_width = 2
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ .ruby-version
14
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/**/*_spec.rb'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ if ENV['COVERAGE']
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ ---
2
+ env:
3
+ global:
4
+ - JRUBY_OPTS='-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-Xss2m -Xcompile.invokedynamic=false'
5
+ - BUNDLER_VERSION='2.1.4'
6
+
7
+ stages:
8
+ - name: test
9
+ if: branch = master AND (tag IS blank)
10
+ - name: publish
11
+ if: branch = master AND type = push
12
+
13
+ rvm:
14
+ - 2.5.7
15
+ - 2.6.5
16
+ - 2.7.0
17
+
18
+ before_install: gem install bundler -v $BUNDLER_VERSION
19
+
20
+ jobs:
21
+ include:
22
+ - stage: test
23
+ language: ruby
24
+ rvm: jruby-9.2.11.1
25
+ jdk: openjdk8
26
+ before_install: gem install bundler -v $BUNDLER_VERSION
27
+
28
+ - stage: publish
29
+ name: "Publish to RubyGems"
30
+ language: ruby
31
+ rvm: 2.7.0
32
+ before_install: gem install bundler -v $BUNDLER_VERSION
33
+ script: ${TRAVIS_BUILD_DIR}/.ci/rubygems_publish.sh
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sayantam@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in croaky-rspec.gemspec
6
+ gemspec
7
+
8
+ group :test, :development do
9
+ gem 'rake', '~> 12.0'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rubocop'
12
+ gem 'simplecov'
13
+ end
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ croaky-rspec (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ diff-lcs (1.4.4)
11
+ docile (1.3.2)
12
+ parallel (1.19.2)
13
+ parser (2.7.1.4)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.0.0)
16
+ rake (12.3.3)
17
+ regexp_parser (1.7.1)
18
+ rexml (3.2.4)
19
+ rspec (3.9.0)
20
+ rspec-core (~> 3.9.0)
21
+ rspec-expectations (~> 3.9.0)
22
+ rspec-mocks (~> 3.9.0)
23
+ rspec-core (3.9.2)
24
+ rspec-support (~> 3.9.3)
25
+ rspec-expectations (3.9.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.9.0)
28
+ rspec-mocks (3.9.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.9.0)
31
+ rspec-support (3.9.3)
32
+ rubocop (0.89.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.7.1.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ regexp_parser (>= 1.7)
37
+ rexml
38
+ rubocop-ast (>= 0.3.0, < 1.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 1.4.0, < 2.0)
41
+ rubocop-ast (0.3.0)
42
+ parser (>= 2.7.1.4)
43
+ ruby-progressbar (1.10.1)
44
+ simplecov (0.19.0)
45
+ docile (~> 1.1)
46
+ simplecov-html (~> 0.11)
47
+ simplecov-html (0.12.2)
48
+ unicode-display_width (1.7.0)
49
+
50
+ PLATFORMS
51
+ java
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ croaky-rspec!
56
+ rake (~> 12.0)
57
+ rspec (~> 3.0)
58
+ rubocop
59
+ simplecov
60
+
61
+ BUNDLED WITH
62
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Sayantam Dey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Croaky::Rspec
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/croaky/rspec`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'croaky-rspec'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install croaky-rspec
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/croaky-rspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/croaky-rspec/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Croaky::Rspec project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/croaky-rspec/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'croaky/rspec'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'croaky/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'croaky-rspec'
9
+ spec.version = Croaky::VERSION
10
+ spec.authors = ['Sayantam Dey']
11
+ spec.email = ['sayantam@gmail.com']
12
+
13
+ spec.summary = 'RSpec formatter that croaks only for failed examples.'
14
+ spec.description = <<-DESC
15
+ Captures stdout and stderr during an example run, and dumps them for failed examples only.
16
+ Progress is shown as per progress formatter
17
+ DESC
18
+ spec.homepage = 'https://github.com/sayantam/croaky-rspec'
19
+ spec.license = 'MIT'
20
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
21
+
22
+ spec.metadata['homepage_uri'] = spec.homepage
23
+ spec.metadata['source_code_uri'] = 'https://github.com/sayantam/croaky-rspec'
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Top level Croaky namespace
4
+ module Croaky
5
+ class Error < StandardError; end
6
+
7
+ # RSpec namespace
8
+ module RSpec; end
9
+
10
+ # IO namespace
11
+ module IO; end
12
+
13
+ # Stream namespace
14
+ module Stream; end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'croaky/io_stream_builder'
4
+
5
+ module Croaky
6
+ # Object builders
7
+ module Builders
8
+ def self.io_stream
9
+ return @io_stream if @io_stream
10
+
11
+ builder = ::Croaky::IoStreamBuilder.new
12
+ @io_stream = builder.build
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'croaky'
4
+
5
+ module Croaky
6
+ module IO
7
+ # Capturable interface
8
+ module IoCapturable
9
+ def capture_io
10
+ # :nocov:
11
+ raise(NotImplementedError, "#{self.class.name}##{__method__}")
12
+ # :nocov:
13
+ end
14
+
15
+ def restore_io
16
+ # :nocov:
17
+ raise(NotImplementedError, "#{self.class.name}##{__method__}")
18
+ # :nocov:
19
+ end
20
+
21
+ def read_captured_io
22
+ # :nocov:
23
+ raise(NotImplementedError, "#{self.class.name}##{__method__}")
24
+ # :nocov:
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'croaky/io/io_capturable'
4
+
5
+ module Croaky
6
+ module IO
7
+ # IO adapter
8
+ class IoStream
9
+ include IoCapturable
10
+
11
+ attr_reader :stdout_stream, :stderr_stream
12
+
13
+ def initialize(stdout_stream, stderr_stream)
14
+ @stdout_stream = stdout_stream
15
+ @stderr_stream = stderr_stream
16
+ end
17
+
18
+ def capture_io
19
+ stdout_stream.capture_io
20
+ stderr_stream.capture_io
21
+ end
22
+
23
+ def restore_io
24
+ stdout_stream.restore_io
25
+ stderr_stream.restore_io
26
+ end
27
+
28
+ def read_captured_io
29
+ captured = [stdout_stream.read_captured_io, stderr_stream.read_captured_io]
30
+ captured.flatten.reject { |s| s.to_s.empty? }.join($INPUT_RECORD_SEPARATOR)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'croaky/io/io_stream'
4
+
5
+ module Croaky
6
+ # Builds an IoStream based on the platform.
7
+ class IoStreamBuilder
8
+ def build
9
+ jruby_platform = defined?(JRUBY_VERSION)
10
+ stdout_stream = jruby_platform ? java_stdout_stream : ruby_stdout_stream
11
+ stderr_stream = jruby_platform ? java_stderr_stream : ruby_stderr_stream
12
+ Croaky::IO::IoStream.new(stdout_stream, stderr_stream)
13
+ end
14
+
15
+ private
16
+
17
+ def ruby_stdout_stream
18
+ require 'croaky/stream/std_out_stream'
19
+ Stream::StdOutStream.new
20
+ end
21
+
22
+ def java_stdout_stream
23
+ require 'croaky/stream/java_std_out_stream'
24
+ Stream::JavaStdOutStream.new
25
+ end
26
+
27
+ def ruby_stderr_stream
28
+ require 'croaky/stream/std_err_stream'
29
+ Stream::StdErrStream.new
30
+ end
31
+
32
+ def java_stderr_stream
33
+ require 'croaky/stream/java_std_err_stream'
34
+ Stream::JavaStdErrStream.new
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec::Support.require_rspec_core 'formatters/base_text_formatter'
4
+ RSpec::Support.require_rspec_core 'formatters/console_codes'
5
+
6
+ require 'croaky/builders'
7
+ require 'croaky/io/io_stream'
8
+
9
+ module Croaky
10
+ module RSpec
11
+ # Croaky formatter
12
+ class CroakyFormatter < ::RSpec::Core::Formatters::BaseTextFormatter
13
+ NOTIFICATIONS = %i[start example_started example_passed example_pending example_failed].freeze
14
+ ::RSpec::Core::Formatters.register(self, *NOTIFICATIONS)
15
+
16
+ COLORIZER = ::RSpec::Core::Formatters::ConsoleCodes
17
+
18
+ attr_reader :io_stream
19
+
20
+ def initialize(output, io_stream = ::Croaky::Builders.io_stream)
21
+ super(output)
22
+
23
+ @io_stream = io_stream
24
+ end
25
+
26
+ def example_started(_notification)
27
+ io_stream.capture_io
28
+ end
29
+
30
+ def example_passed(_notification)
31
+ io_stream.restore_io
32
+ output.print COLORIZER.wrap('.', :success)
33
+ end
34
+
35
+ def example_pending(_notification)
36
+ io_stream.restore_io
37
+ output.print COLORIZER.wrap('*', :pending)
38
+ end
39
+
40
+ # @param [RSpec::Core::Notifications::FailedExampleNotification] notification
41
+ def example_failed(notification)
42
+ io_stream.restore_io
43
+
44
+ class << notification.example
45
+ attr_accessor :captured_io
46
+ end
47
+
48
+ notification.example.captured_io = io_stream.read_captured_io
49
+ output.print COLORIZER.wrap('F', :failure)
50
+ end
51
+
52
+ # @param [RSpec::Core::Notifications::ExamplesNotification] notification
53
+ def dump_failures(notification)
54
+ return if notification.failure_notifications.empty?
55
+
56
+ output.puts
57
+ output.puts 'Failures:'
58
+ notification.failure_notifications.each_with_index do |failure, index|
59
+ output.puts failure.fully_formatted(index.next, COLORIZER)
60
+ output.puts failure.example.captured_io
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'croaky/stream/std_err_stream'
4
+
5
+ module Croaky
6
+ module Stream
7
+ # Error stream for Java
8
+ class JavaStdErrStream < StdErrStream
9
+ attr_accessor :pw_err, :java_stderr
10
+
11
+ def capture_io
12
+ super
13
+
14
+ self.java_stderr = java.lang.System.err
15
+ pw_err&.close
16
+ self.pw_err = err_stream
17
+ java.lang.System.setErr(pw_err)
18
+ end
19
+
20
+ def restore_io
21
+ super
22
+
23
+ java.lang.System.setErr(java_stderr)
24
+ pw_err.close
25
+ end
26
+
27
+ def read_captured_io
28
+ captured = super
29
+
30
+ captured << read_err_stream
31
+ end
32
+
33
+ private
34
+
35
+ def err_stream
36
+ @err_stream = java.io.ByteArrayOutputStream.new
37
+ java.io.PrintStream.new(@err_stream)
38
+ end
39
+
40
+ def read_err_stream
41
+ @err_stream.to_string('utf-8')
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'croaky/stream/std_out_stream'
4
+
5
+ module Croaky
6
+ module Stream
7
+ JAVA_LANG = java.lang
8
+
9
+ # Output stream for Java
10
+ class JavaStdOutStream < StdOutStream
11
+ attr_accessor :pw_out, :java_stdout
12
+
13
+ def capture_io
14
+ super
15
+
16
+ self.java_stdout = java.lang.System.out
17
+ pw_out&.close
18
+ self.pw_out = out_stream
19
+ java.lang.System.setOut(pw_out)
20
+ end
21
+
22
+ def restore_io
23
+ super
24
+
25
+ java.lang.System.setOut(java_stdout)
26
+ pw_out.close
27
+ end
28
+
29
+ def read_captured_io
30
+ captured = super
31
+
32
+ captured << read_out_stream
33
+ end
34
+
35
+ private
36
+
37
+ def out_stream
38
+ @out_stream = java.io.ByteArrayOutputStream.new
39
+ java.io.PrintStream.new(@out_stream)
40
+ end
41
+
42
+ def read_out_stream
43
+ @out_stream.to_string('utf-8')
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+
5
+ require 'croaky/io/io_capturable'
6
+
7
+ module Croaky
8
+ module Stream
9
+ # Standard error stream
10
+ class StdErrStream
11
+ include ::Croaky::IO::IoCapturable
12
+
13
+ attr_accessor :stderr_str_io
14
+
15
+ def capture_io
16
+ self.stderr_str_io = StringIO.new
17
+ $stderr = stderr_str_io
18
+ end
19
+
20
+ def restore_io
21
+ $stderr = STDERR
22
+ end
23
+
24
+ def read_captured_io
25
+ [stderr_str_io.string]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+
5
+ require 'croaky/io/io_capturable'
6
+
7
+ module Croaky
8
+ module Stream
9
+ # Standard output stream
10
+ class StdOutStream
11
+ include ::Croaky::IO::IoCapturable
12
+
13
+ attr_accessor :stdout_str_io
14
+
15
+ def capture_io
16
+ self.stdout_str_io = StringIO.new
17
+ $stdout = stdout_str_io
18
+ end
19
+
20
+ def restore_io
21
+ $stdout = STDOUT
22
+ end
23
+
24
+ def read_captured_io
25
+ [stdout_str_io.string]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'croaky'
4
+
5
+ module Croaky
6
+ VERSION = '0.1.0'
7
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: croaky-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sayantam Dey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2
14
+ Captures stdout and stderr during an example run, and dumps them for failed examples only.
15
+ Progress is shown as per progress formatter
16
+ email:
17
+ - sayantam@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".ci/rubygems_publish.sh"
23
+ - ".editorconfig"
24
+ - ".gitignore"
25
+ - ".rspec"
26
+ - ".rubocop.yml"
27
+ - ".simplecov"
28
+ - ".travis.yml"
29
+ - CODE_OF_CONDUCT.md
30
+ - Gemfile
31
+ - Gemfile.lock
32
+ - LICENSE.txt
33
+ - README.md
34
+ - Rakefile
35
+ - bin/console
36
+ - bin/setup
37
+ - croaky-rspec.gemspec
38
+ - lib/croaky.rb
39
+ - lib/croaky/builders.rb
40
+ - lib/croaky/io/io_capturable.rb
41
+ - lib/croaky/io/io_stream.rb
42
+ - lib/croaky/io_stream_builder.rb
43
+ - lib/croaky/rspec/croaky_formatter.rb
44
+ - lib/croaky/stream/java_std_err_stream.rb
45
+ - lib/croaky/stream/java_std_out_stream.rb
46
+ - lib/croaky/stream/std_err_stream.rb
47
+ - lib/croaky/stream/std_out_stream.rb
48
+ - lib/croaky/version.rb
49
+ homepage: https://github.com/sayantam/croaky-rspec
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/sayantam/croaky-rspec
54
+ source_code_uri: https://github.com/sayantam/croaky-rspec
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.3.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: RSpec formatter that croaks only for failed examples.
74
+ test_files: []