towel-rspec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6cc10be7a1c89656bbd2a694f453970eada08fe806ebcec895909256b4f6955b
4
+ data.tar.gz: c6554e265d94defbecbe57648109009327783002a5d7c9b91da733a4b39adf43
5
+ SHA512:
6
+ metadata.gz: dad5755c7d1c22541c2455291d54a3de3b655d4a69ecdc7714ec679f9846ae2f3d31e5f4a704e660fd8a8a7c91f469e6ae5b0384d96138919ef5057ae2948e4e
7
+ data.tar.gz: 2618ee82ffdbd5099ea43730a6ac5f569f3082d9345fa3e19d27f4a852efb914594911fee0fcd7f4f45b456a49dd20c29b16ac87877b37cdd84a969847829ab4
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in towel-rspec.gemspec
6
+ gemspec
@@ -0,0 +1,43 @@
1
+ # Towel::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/towel/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 'towel-rspec'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install towel-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 test` 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]/towel-rspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Towel::Rspec project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/towel-rspec/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "towel/rspec"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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,3 @@
1
+ --no-color
2
+ --require towel/rspec
3
+ --format Towel::RSpec::Formatter
@@ -0,0 +1,39 @@
1
+ # This is an example configuration file for Towel. It shows most of the
2
+ # different options that can be set, even though a normal config file will only
3
+ # have a subset of options specified. Towel uses TOML for configuration. It's a
4
+ # lot like INI, but well-defined. To get a feel for the syntax, look at
5
+ # https://github.com/toml-lang/toml/blob/v0.5.0/README.md
6
+
7
+
8
+ [auth]
9
+ # The Towel account that is reporting invocations. This is how your invocations
10
+ # are linked to you.
11
+ account = "wile.e.coyote@acme.corp"
12
+
13
+ # The API key to communicate with. DO NOT commit this or make this public to
14
+ # others that you do not want them to be able to report to Towel.
15
+ api_key = "AezKF3gPPyzD8dvgDYFYF9we5YP4R87UqhTzDxs3CnkY"
16
+
17
+
18
+ [collector]
19
+ # Where should results be reported to. This should be a hostname and port if
20
+ # non-standard (443). This allows you to point against different Towel instances
21
+ # (staging for example).
22
+ address = "localhost:10081"
23
+
24
+ # The organization handle for the organization that holds your Towel projects.
25
+ organization = "acme"
26
+
27
+ # The project handle for the project that invocations should be reported under.
28
+ project = "dynamite"
29
+
30
+
31
+ # This section is free-form. You can add whatever labels you would like to
32
+ # appear on all invocations reported using this configuration. This is useful
33
+ # for per-branch or per-environment annotations. NOTE: Only string values are
34
+ # allowed here.
35
+ [labels]
36
+ branch = "master"
37
+ environment = "test"
38
+ language = "ruby"
39
+ framework = "rspec"
@@ -0,0 +1,24 @@
1
+ Foo = Class.new
2
+
3
+ RSpec.describe Foo do
4
+ describe "#foo" do
5
+ it "acts normally" do
6
+ puts "OK"
7
+ end
8
+
9
+ it "stays cool"
10
+ it "never gives up" do
11
+ sleep 10
12
+ end
13
+ end
14
+
15
+ describe "#bar" do
16
+ it "is a little unsure of itself" do
17
+ raise ArgumentError, "Not sure of myself"
18
+ end
19
+
20
+ it "needs affirmation" do
21
+ expect(false).to eq(true)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ # Gems
2
+ require "rspec/core"
3
+ require "towel"
4
+
5
+ require "towel/rspec/formatter"
6
+ require "towel/rspec/version"
7
+
8
+ module Towel
9
+ module RSpec
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+ end
13
+ end
@@ -0,0 +1,123 @@
1
+ require "rspec/core/formatters/base_formatter"
2
+
3
+ module Towel
4
+ module RSpec
5
+ # Takes RSpec events and turns them into a streaming upload to Towel.
6
+ class Formatter < ::RSpec::Core::Formatters::BaseFormatter
7
+ ::RSpec::Core::Formatters.register self, :start,
8
+ :example_started,
9
+ :example_finished,
10
+ :close
11
+
12
+ def initialize(io)
13
+ super
14
+ @session = Towel::Session.new
15
+ @stdout = nil
16
+ @stderr = nil
17
+ @previous_stdout = nil
18
+ @previous_stderr = nil
19
+ @cancel_queue = Queue.new
20
+
21
+ # Start a thread to listen for cancellations. Cancel the invocation if
22
+ # requested. This exists because gRPC requests may not be made directly
23
+ # from within a signal handler. It appears that RSpec shutdown runs as
24
+ # such.
25
+ Thread.new do
26
+ cancelled = @cancel_queue.pop
27
+ @session.cancel_invocation if cancelled
28
+ end
29
+ end
30
+
31
+ def start(_notification)
32
+ super
33
+
34
+ url = @session.create_invocation
35
+ puts "View test results at #{url}"
36
+
37
+ # Register a cancellation handler
38
+ old_handler = Signal.trap("INT") do
39
+ @cancel_queue << true
40
+ # Mark the queue as closed so that other observers can determine if
41
+ # the run has been cancelled or not.
42
+ @cancel_queue.close
43
+ if old_handler.respond_to?(:call)
44
+ old_handler.call
45
+ else
46
+ raise Interrupt
47
+ end
48
+ end
49
+
50
+ # Capture logs
51
+ @previous_stdout = $stdout
52
+ $stdout = @stdout = Towel::LogIO.new(@session.create_log("STDOUT"))
53
+ @previous_stderr = $stderr
54
+ $stderr = @stderr = Towel::LogIO.new(@session.create_log("STDERR"))
55
+ end
56
+
57
+ def example_started(notification)
58
+ example_group = notification.example.example_group
59
+ example = notification.example
60
+ group = example_group.described_class.to_s + example_group.description
61
+
62
+ context = @session.create_result(
63
+ group,
64
+ example.id,
65
+ display_name: example.description
66
+ )
67
+
68
+ @stdout.context = context
69
+ @stderr.context = context
70
+ end
71
+
72
+ def example_finished(notification)
73
+ example_group = notification.example.example_group
74
+ example = notification.example
75
+ group = example_group.described_class.to_s + example_group.description
76
+
77
+ state = case example.execution_result.status
78
+ when :passed then Towel::V1alpha::ResultState::SUCCESS
79
+ when :failed then Towel::V1alpha::ResultState::FAILURE
80
+ when :pending then Towel::V1alpha::ResultState::SKIPPED
81
+ end
82
+
83
+ duration = nil
84
+ unless state == Towel::V1alpha::ResultState::SKIPPED
85
+ duration = example.execution_result.run_time
86
+ end
87
+
88
+ description = nil
89
+ if state == Towel::V1alpha::ResultState::SKIPPED
90
+ description = example.execution_result.pending_message
91
+ elsif state == Towel::V1alpha::ResultState::FAILURE
92
+ description = example.execution_result.exception.message
93
+ end
94
+
95
+ # Cannot make a gRPC call from a signal handler, so check to make sure
96
+ # we aren't operating from one.
97
+ unless @cancel_queue.closed?
98
+ @session.update_result(
99
+ group,
100
+ example.id,
101
+ state: state,
102
+ duration: duration,
103
+ description: description
104
+ )
105
+ end
106
+
107
+ @stdout.context = nil
108
+ @stderr.context = nil
109
+ end
110
+
111
+ def close(_notification)
112
+ super
113
+
114
+ $stdout = @previous_stdout
115
+ $stderr = @previous_stderr
116
+
117
+ unless @cancel_queue.closed?
118
+ @session.finish_invocation
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,5 @@
1
+ module Towel
2
+ module RSpec
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "towel/rspec/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "towel-rspec"
8
+ spec.version = Towel::RSpec::VERSION
9
+ spec.authors = ["Andrew Smith"]
10
+ spec.email = ["andrew@velvet.software"]
11
+
12
+ spec.summary = "Towel integration for collecting results from RSpec"
13
+ spec.description = <<END
14
+ Towel collects test results as they run, reporting them to towel.dev for easier
15
+ inspection, debugging, and sharing.
16
+ END
17
+ spec.homepage = "https://towel.dev"
18
+ spec.license = "MIT"
19
+
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://bitbucket.org/VelvetSoftware/towel-ruby"
23
+ spec.metadata["changelog_uri"] = "https://bitbucket.org/VelvetSoftware/towel-ruby/src/master/extensions/towel-rspec/CHANGELOG.md"
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_dependency "rspec-core", "~> 3"
36
+ spec.add_dependency "towel", "~> 0.1"
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3"
41
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: towel-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: towel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ description: |
84
+ Towel collects test results as they run, reporting them to towel.dev for easier
85
+ inspection, debugging, and sharing.
86
+ email:
87
+ - andrew@velvet.software
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - examples/.rspec
100
+ - examples/.towel.toml
101
+ - examples/simple_spec.rb
102
+ - lib/towel/rspec.rb
103
+ - lib/towel/rspec/formatter.rb
104
+ - lib/towel/rspec/version.rb
105
+ - towel-rspec.gemspec
106
+ homepage: https://towel.dev
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ homepage_uri: https://towel.dev
111
+ source_code_uri: https://bitbucket.org/VelvetSoftware/towel-ruby
112
+ changelog_uri: https://bitbucket.org/VelvetSoftware/towel-ruby/src/master/extensions/towel-rspec/CHANGELOG.md
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.0.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Towel integration for collecting results from RSpec
132
+ test_files: []