rspec-daemon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad0427bfd2ee9e38d83573209c7d4166e2679e8c4dcffbf4ca48f4312e4d3752
4
+ data.tar.gz: 89a1eca7a74ad6b2242e5f5fe49a827e43b89ee785e6437a67476c4d6d97da98
5
+ SHA512:
6
+ metadata.gz: 7863bb3e3b787ea85ebba9d5cd71b7960882504c7a0e538a1f1262bf1d5e991da725cbeb751d748dcda4496236feceb3929acc6748248cc970858e20cdadaee7
7
+ data.tar.gz: 1a596832de5d47be88d9f151a87532ab721241ed87d7641474477e9fca7ea852ccb6f1dd6467ee0c152cf4b5acdec2defdc7d5397bff96f20c5857215fe9b4da
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: "https://raw.githubusercontent.com/cookpad/styleguide/master/.rubocop.yml"
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-04-11
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at asonas@cookpad.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rspec-daemon.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Yuya Fujiwara
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.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Rspec::Daemon
2
+
3
+ rspec-daemon is a gem to run specs at high speed.
4
+
5
+ The original idea can be found at the following URL @cumet04
6
+ https://gist.github.com/cumet04/71d7d76310f7cb436c68b57a7c99aae3
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ require 'rspec-daemon', require: false
12
+ ```
13
+
14
+ ## Usage
15
+
16
+
17
+ ```
18
+ $ bundle ex rspec-daemon
19
+ ```
20
+
21
+ ```
22
+ $ echo 'spec/models/brand_spec.rb' | nc -v 0.0.0.0 3002
23
+ ```
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/asonas/rspec-daemon. 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/asonas/rspec-daemon/blob/master/CODE_OF_CONDUCT.md).
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the Rspec::Daemon project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/asonas/rspec-daemon/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/example/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rspec'
4
+ gem 'rspec-daemon', path: '/Users/asonas@cookpad.com/ghq/github.com/asonas/rspec-daemon'
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: /Users/asonas@cookpad.com/ghq/github.com/asonas/rspec-daemon
3
+ specs:
4
+ rspec-daemon (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.5.0)
10
+ rspec (3.12.0)
11
+ rspec-core (~> 3.12.0)
12
+ rspec-expectations (~> 3.12.0)
13
+ rspec-mocks (~> 3.12.0)
14
+ rspec-core (3.12.1)
15
+ rspec-support (~> 3.12.0)
16
+ rspec-expectations (3.12.2)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.12.0)
19
+ rspec-mocks (3.12.5)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.12.0)
22
+ rspec-support (3.12.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ rspec
29
+ rspec-daemon!
30
+
31
+ BUNDLED WITH
32
+ 2.3.26
@@ -0,0 +1,23 @@
1
+ class User
2
+ attr_accessor :birthday
3
+
4
+ def initialize(birthday)
5
+ @birthday = birthday
6
+ end
7
+
8
+ def age
9
+ 34
10
+ end
11
+ end
12
+
13
+ Rspec.describe "User" do
14
+ describe "#age" do
15
+ before do
16
+ @user = User.new(Time.new(1988, 11, 7))
17
+ end
18
+
19
+ it "should return 34" do
20
+ expect(@user.age).to eql 34
21
+ end
22
+ end
23
+ end
data/exe/rspec-daemon ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rspec/daemon/cli'
4
+ Rspec::Daemon::Cli.start
@@ -0,0 +1,11 @@
1
+ require_relative '../daemon'
2
+
3
+ module RSpec
4
+ class Daemon
5
+ class Cli
6
+ def self.start
7
+ RSpec::Daemon.start
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,69 @@
1
+ module RSpec
2
+ class Daemon
3
+ class Configuration
4
+ attr_accessor :config_proxy, :root_shared_examples
5
+
6
+ class RecordingProxy < Struct.new(:target, :recorded_messages)
7
+ [:include, :extend].each do |method|
8
+ define_method(method) do |*args|
9
+ method_missing(method, *args)
10
+ end
11
+ end
12
+
13
+ def method_missing(method, *args, &block)
14
+ self.recorded_messages << [method, args, block]
15
+ self.target.send(method, *args, &block)
16
+ end
17
+ end
18
+
19
+ def record_configuration(&configuration_block)
20
+ ensure_configuration_setter!
21
+
22
+ original_config = ::RSpec.configuration
23
+ RSpec.configuration = RecordingProxy.new(original_config, [])
24
+
25
+ configuration_block.call # spec helper is called during this yield, see #reset
26
+
27
+ self.config_proxy = ::RSpec.configuration
28
+ RSpec.configuration = original_config
29
+
30
+ forward_rspec_config_singleton_to(self.config_proxy)
31
+ end
32
+
33
+ def replay_configuration
34
+ RSpec.configure do |config|
35
+ self.config_proxy.recorded_messages.each do |method, args, block|
36
+ # reporter caches config.output_stream which is not good as it
37
+ # prevents the runner to use a custom stdout.
38
+ next if method == :reporter
39
+
40
+ config.send(method, *args, &block)
41
+ end
42
+ end
43
+
44
+ forward_rspec_config_singleton_to(self.config_proxy)
45
+ end
46
+
47
+ def has_recorded_config?
48
+ !!self.config_proxy
49
+ end
50
+
51
+ def forward_rspec_config_singleton_to(config_proxy)
52
+ # an old version of rspec-rails/lib/rspec/rails/view_rendering.rb adds
53
+ # methods on the configuration singleton. This takes care of that.
54
+ RSpec.configuration.singleton_class
55
+ .send(:define_method, :method_missing, &config_proxy.method(:send))
56
+ end
57
+
58
+ def ensure_configuration_setter!
59
+ return if RSpec.respond_to?(:configuration=)
60
+
61
+ RSpec.instance_eval do
62
+ def self.configuration=(value)
63
+ @configuration = value
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ class Daemon
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "daemon/version"
4
+ require_relative "daemon/configuration"
5
+
6
+ require "socket"
7
+ require "stringio"
8
+ require "rspec"
9
+ require "pry"
10
+
11
+ module RSpec
12
+ class Daemon
13
+ SCRIPT_NAME = File.basename(__FILE__).freeze
14
+
15
+ class Error < StandardError; end
16
+
17
+ def self.start
18
+ self.new.start
19
+ end
20
+
21
+ def start
22
+ entry_point
23
+ end
24
+
25
+ def entry_point
26
+ $LOAD_PATH << "./spec"
27
+
28
+ RSpec::Core::Runner.disable_autorun!
29
+ server = TCPServer.open("0.0.0.0", 3002)
30
+
31
+ loop do
32
+ handle_request(server.accept)
33
+ rescue Interrupt
34
+ puts "quit"
35
+ server.close
36
+ break
37
+ end
38
+ end
39
+
40
+ def handle_request(socket)
41
+ status, out = run(socket.read)
42
+
43
+ socket.puts(status)
44
+ socket.puts(out)
45
+ socket.puts(__FILE__)
46
+ rescue StandardError => e
47
+ socket.puts e.full_message
48
+ ensure
49
+ socket.close
50
+ end
51
+
52
+ def run(msg, options = [])
53
+ options += ["--force-color"]
54
+ argv = msg.split(" ")
55
+
56
+ reset
57
+ out = StringIO.new
58
+ status = RSpec::Core::Runner.run(options + argv, out, out)
59
+
60
+ [status, out.string]
61
+ end
62
+
63
+ def reset
64
+ RSpec::Core::Configuration.class_eval { define_method(:command) { "rspec" } }
65
+ RSpec::Core::Runner.disable_autorun!
66
+ RSpec.reset
67
+
68
+ if cached_config.has_recorded_config?
69
+ cached_config.replay_configuration
70
+ else
71
+ cached_config.record_configuration(&rspec_configuration)
72
+ end
73
+ end
74
+
75
+ def rspec_configuration
76
+ proc do
77
+ require "rails_helper"
78
+ end
79
+ end
80
+
81
+ def cached_config
82
+ @cached_config ||= Rspec::Daemon::Configuration.new
83
+ end
84
+
85
+ RSpec::Core::BacktraceFormatter.class_eval do
86
+ def format_backtrace(backtrace, options = {})
87
+ return [] unless backtrace
88
+ return backtrace if options[:full_backtrace] || backtrace.empty?
89
+
90
+ backtrace.map { |l| backtrace_line(l) }.compact.inject([]) do |result, line|
91
+ break result if line.include?(SCRIPT_NAME)
92
+
93
+ result << line
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rspec/daemon/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rspec-daemon"
7
+ spec.version = RSpec::Daemon::VERSION
8
+ spec.authors = ["Yuya Fujiwara"]
9
+ spec.email = ["asonas@cookpad.com"]
10
+
11
+ spec.summary = "rspec-daemon is a mechanism to run tests at super faster speed"
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/asonas/rspec-daemon"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/asonas/rspec-daemon"
19
+ spec.metadata["changelog_uri"] = "https://github.com/asonas/rspec-daemon/blob/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
@@ -0,0 +1,6 @@
1
+ module Rspec
2
+ module Daemon
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-daemon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuya Fujiwara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email:
15
+ - asonas@cookpad.com
16
+ executables:
17
+ - rspec-daemon
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - example/Gemfile
30
+ - example/Gemfile.lock
31
+ - example/user_spec.rb
32
+ - exe/rspec-daemon
33
+ - lib/rspec/daemon.rb
34
+ - lib/rspec/daemon/cli.rb
35
+ - lib/rspec/daemon/configuration.rb
36
+ - lib/rspec/daemon/version.rb
37
+ - rspec-daemon.gemspec
38
+ - sig/rspec/daemon.rbs
39
+ homepage: https://github.com/asonas/rspec-daemon
40
+ licenses:
41
+ - MIT
42
+ metadata:
43
+ homepage_uri: https://github.com/asonas/rspec-daemon
44
+ source_code_uri: https://github.com/asonas/rspec-daemon
45
+ changelog_uri: https://github.com/asonas/rspec-daemon/blob/master/CHANGELOG.md
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.3.26
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: rspec-daemon is a mechanism to run tests at super faster speed
65
+ test_files: []