rspec-daemon 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '009bb553fc685bd3c43c8317afa829b91927d113f4a82c3ba225a25c6b222b97'
4
- data.tar.gz: 617b4b819820308641bdcbbdb1700b95a4b881cc531bc1b40f6333d1daca94ab
3
+ metadata.gz: 208bd76b8815eaf702f7b32c3cfd987551c122d49e63f8f7c2bd912c84e81b31
4
+ data.tar.gz: 96b0bae9c7f30441345b8e85419be284fdecb1d112e7ae842ccd76c26c1b476d
5
5
  SHA512:
6
- metadata.gz: 8452ebf8fb216e146f5541c781f44b1d75ce9253c3d31bccf4578e63f7cad54858faff131dc3c133c359f797f25a9a7ee39f1fd6a85070662a2ead7bb5b5508f
7
- data.tar.gz: bce7470abe76132de68bf3076678a82f1366bed74a0345c7a0617bdb9a9151d8d97b3d2474f24c06bf477fac442235566e51e0e17e2df9d3ac8943ebc6ce44bc
6
+ metadata.gz: 2fc0fc6bded50693fd5db0e9f8d05fb7cb9980a146467548a1889f7e1435623947b67b5decb5baea37e65b2c0c7fc99b9c224a16968020964a46f013542625b9
7
+ data.tar.gz: c22c13bd14953714bc393ea81423895a94a310be7c4e10d0d2ed49af3d021d179cb5335b6d505fa1cf22c481fd11f1cc26fb1a8cdab6628b2a1e70a9a8dce245
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0]
4
+
5
+ - Make bind address and port configurable #7 @osyoyu
6
+ - Remove pry dependency #6 @osyoyu
7
+ - rspeccc, a client tool for rspec-daemon #5 @osyoyu
8
+ - allow configuration of port via env #4 @felixRun
9
+
3
10
  ## [0.1.0] - 2023-04-11
4
11
 
5
12
  - Initial release
data/README.md CHANGED
@@ -15,15 +15,85 @@ gem 'rspec-daemon', require: false
15
15
 
16
16
  ## Usage
17
17
 
18
+ Start the daemon process by running `rspec-daemon` in the directory where you would run `rspec`.
19
+
18
20
  ```
19
21
  $ cd YOUR_PROJECT
20
22
  $ bundle ex rspec-daemon
23
+ Listening on tcp://0.0.0.0:3002
24
+ ```
25
+
26
+ To run specs, use the `rspeccc` client tool.
27
+
28
+ ```
29
+ $ bundle ex rspeccc spec/models/user_spec.rb # arguments are passed to rspec
30
+
31
+ User
32
+ is healthy
33
+
34
+ Finished in 0.00136 seconds (files took 36.25 seconds to load)
35
+ 1 example, 0 failures
21
36
  ```
22
37
 
38
+ Alternatively, standard utilites such as `nc` may be used.
39
+
23
40
  ```
24
41
  $ echo 'spec/models/user_spec.rb' | nc -v 0.0.0.0 3002
25
42
  ```
26
43
 
44
+ By default, `rspec-daemon` will run on port `3002`. You can adjust the port by passing `--port` to `rspec-daemon` or setting the `RSPEC_DAEMON_PORT` environment variable.
45
+
46
+ ## Editor integration
47
+
48
+ ### Vim/Neovim
49
+
50
+ Add a key binding of your preference to your `.vimrc` or `init.vim`.
51
+
52
+ ```vim
53
+ " Run specs under the current cursor line
54
+ nnoremap <Leader>h :execute '!bundle exec rspeccc ' . expand('%:p') . ':' . line('.')<CR>
55
+ ```
56
+
57
+ If you are using [rspec.vim](https://github.com/thoughtbot/vim-rspec), you may want to configure `g:rspec_command`.
58
+
59
+ ```vim
60
+ " For rspec.vim users
61
+ let g:rspec_command = "!bundle exec rspeccc {spec}"
62
+ ```
63
+
64
+ ### Visual Studio Code
65
+
66
+ Tasks are a nice way to launch `rspeccc`.
67
+ Here is an example `tasks.json` configuration which runs specs under the current cursor location:
68
+
69
+ ```json
70
+ {
71
+ "version": "2.0.0",
72
+ "tasks": [
73
+ {
74
+ "label": "rspec-remote: Cursor context",
75
+ "group": "test",
76
+ "type": "shell",
77
+ "command": "bundle exec rspeccc ${relativeFile}:${lineNumber}"
78
+ }
79
+ ]
80
+ }
81
+ ```
82
+
83
+ Adding a keybindings.json entry for your Task is also recommendable.
84
+
85
+ ```json
86
+ [
87
+ {
88
+ "key": "cmd+h",
89
+ "command": "workbench.action.tasks.runTask",
90
+ "args": "rspec-remote: Cursor context"
91
+ }
92
+ ]
93
+ ```
94
+
95
+ Refer to Visual Studio Code's documentation ([Integrate with External Tools via Tasks](https://go.microsoft.com/fwlink/?LinkId=733558)) for further customization.
96
+
27
97
  ## Development
28
98
 
29
99
  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.
data/exe/rspec-daemon CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rspec/daemon/cli'
4
- RSpec::Daemon::Cli.start
4
+ RSpec::Daemon::Cli.start(ARGV)
data/exe/rspeccc ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rspec/daemon/client_cli'
4
+ exit RSpec::Daemon::ClientCli.run(ARGV)
@@ -3,8 +3,42 @@ require_relative '../daemon'
3
3
  module RSpec
4
4
  class Daemon
5
5
  class Cli
6
- def self.start
7
- RSpec::Daemon.start
6
+ DEFAULT_OPTIONS = {
7
+ bind_address: "0.0.0.0",
8
+ port: 3002,
9
+ }
10
+
11
+ def self.start(...)
12
+ new.start(...)
13
+ end
14
+
15
+ def start(argv)
16
+ options = DEFAULT_OPTIONS.dup
17
+ if ENV['RSPEC_DAEMON_BIND_ADDRESS']
18
+ options[:bind_address] = ENV['RSPEC_DAEMON_BIND_ADDRESS']
19
+ end
20
+ if ENV['RSPEC_DAEMON_PORT']
21
+ options[:port] = ENV['RSPEC_DAEMON_PORT'].to_i
22
+ end
23
+
24
+ option_parser = OptionParser.new do |opts|
25
+ opts.on('-v', '--version', 'Prints version') do
26
+ puts RSpec::Daemon::VERSION
27
+ exit
28
+ end
29
+
30
+ opts.on('-b', '--bind ADDRESS', 'address to bind (default: 0.0.0.0)') do |address|
31
+ options[:bind_address] = address
32
+ end
33
+
34
+ opts.on('-p', '--port PORT', 'port to listen on (default: 3002)') do |port|
35
+ options[:port] = port
36
+ end
37
+ end
38
+ option_parser.parse!(argv)
39
+
40
+ RSpec::Daemon.new(options[:bind_address], options[:port]).start
41
+ 0
8
42
  end
9
43
  end
10
44
  end
@@ -0,0 +1,52 @@
1
+ require_relative '../daemon'
2
+
3
+ module RSpec
4
+ class Daemon
5
+ class ClientCli
6
+ DEFAULT_OPTIONS = {
7
+ host: "localhost",
8
+ port: 3002,
9
+ }
10
+
11
+ def self.start(...)
12
+ new.start(...)
13
+ end
14
+
15
+ def start(argv)
16
+ options = DEFAULT_OPTIONS.dup
17
+ option_parser = OptionParser.new do |opts|
18
+ opts.on('-v', '--version', 'Prints version') do
19
+ puts RSpec::Daemon::VERSION
20
+ exit
21
+ end
22
+
23
+ opts.on('-h', '--host HOST', 'rspec-daemon host (default: localhost)') do |host|
24
+ options[:host] = host
25
+ end
26
+
27
+ opts.on('-p', '--port PORT', 'rspec-daemon port (default: 3002)') do |port|
28
+ options[:port] = port
29
+ end
30
+ end
31
+ option_parser.parse!(argv)
32
+ # Send all other arguments to rspec via the daemon
33
+ command = argv.join(' ') + "\n"
34
+
35
+ begin
36
+ # Open connection to rspec-daemon
37
+ socket = TCPSocket.open(options[:host], options[:port])
38
+ socket.write(command)
39
+ while line = socket.gets # rubocop:disable Lint/AssignmentInCondition
40
+ print line
41
+ end
42
+ socket.close
43
+ rescue Errno::ECONNREFUSED => e
44
+ STDERR.puts "Failed to connect to #{options[:host]}:#{options[:port]} (#{e})"
45
+ return 1
46
+ end
47
+
48
+ 0
49
+ end
50
+ end
51
+ end
52
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  class Daemon
5
- VERSION = "0.1.4"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
data/lib/rspec/daemon.rb CHANGED
@@ -6,7 +6,6 @@ require_relative "daemon/configuration"
6
6
  require "socket"
7
7
  require "stringio"
8
8
  require "rspec"
9
- require "pry"
10
9
 
11
10
  module RSpec
12
11
  class Daemon
@@ -14,20 +13,17 @@ module RSpec
14
13
 
15
14
  class Error < StandardError; end
16
15
 
17
- def self.start
18
- self.new.start
16
+ def initialize(bind_address, port)
17
+ @bind_address = bind_address
18
+ @port = port
19
19
  end
20
20
 
21
21
  def start
22
- entry_point
23
- end
24
-
25
- def entry_point
26
22
  $LOAD_PATH << "./spec"
27
23
 
28
24
  RSpec::Core::Runner.disable_autorun!
29
- server = TCPServer.open("0.0.0.0", 3002)
30
- puts "start tcp server"
25
+ server = TCPServer.open(@bind_address, @port)
26
+ puts "Listening on tcp://#{server.addr[2]}:#{server.addr[1]}"
31
27
 
32
28
  loop do
33
29
  handle_request(server.accept)
@@ -39,7 +35,7 @@ module RSpec
39
35
  end
40
36
 
41
37
  def handle_request(socket)
42
- status, out = run(socket.read)
38
+ status, out = run(socket.gets)
43
39
 
44
40
  socket.puts(status)
45
41
  socket.puts(out)
@@ -76,7 +72,7 @@ module RSpec
76
72
 
77
73
  def rspec_configuration
78
74
  proc do
79
- if defined?(::Rails)
75
+ if File.exist? "spec/rails_helper.rb"
80
76
  require "rails_helper"
81
77
  end
82
78
  end
data/rspec-daemon.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  # Uncomment to register a new dependency of your gem
33
33
  spec.add_dependency "rspec"
34
- spec.add_dependency "pry"
34
+ spec.add_development_dependency "pry"
35
35
 
36
36
  # For more information and examples about making a new gem, check out our
37
37
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuya Fujiwara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-06 00:00:00.000000000 Z
11
+ date: 2023-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -43,6 +43,7 @@ email:
43
43
  - asonas@cookpad.com
44
44
  executables:
45
45
  - rspec-daemon
46
+ - rspeccc
46
47
  extensions: []
47
48
  extra_rdoc_files: []
48
49
  files:
@@ -58,8 +59,10 @@ files:
58
59
  - example/Gemfile.lock
59
60
  - example/user_spec.rb
60
61
  - exe/rspec-daemon
62
+ - exe/rspeccc
61
63
  - lib/rspec/daemon.rb
62
64
  - lib/rspec/daemon/cli.rb
65
+ - lib/rspec/daemon/client_cli.rb
63
66
  - lib/rspec/daemon/configuration.rb
64
67
  - lib/rspec/daemon/version.rb
65
68
  - rspec-daemon.gemspec
@@ -86,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
89
  - !ruby/object:Gem::Version
87
90
  version: '0'
88
91
  requirements: []
89
- rubygems_version: 3.3.26
92
+ rubygems_version: 3.4.6
90
93
  signing_key:
91
94
  specification_version: 4
92
95
  summary: rspec-daemon is a mechanism to run tests at super faster speed