rspec-watcher 0.2.1 → 0.3.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: f9a41ee072bb0c0c9e649e1a1513709ae253e08b8c8032079eed9b59e87f3261
4
- data.tar.gz: e405302ba9cdfab0e69f2a0805b2ede9f34df5f5eac4ef3591c210acb317137e
3
+ metadata.gz: 298785cbb1ce4aa2e1bbd5cf68e6b2e00537cb4395b738f6d10823703de22ed5
4
+ data.tar.gz: 770ed8be7ea9c8ec239147669b6b4751d436467f30c2f15a825db8c777bee822
5
5
  SHA512:
6
- metadata.gz: de7843b4b6b91c445d1382269d93cdca4f22b1bf053a0c5bf73dbfdcf3ec799e525a560c1488d4dfca5f3a4a7cc9c2bbc0a8ff7e60b6f45a8b9a9f36cb2762c2
7
- data.tar.gz: 1293ed84837d6c56a09a1d04577e8444699f5c2098a4544a0d80e9a77349d47e80238680d55b338b3a86060b4d3a4e9cc5240a8bac9b95497a08ee480b2ae67a
6
+ metadata.gz: 10868133ea19816f38a8688f35cdf2e586e6ff9cd1a456777f603ba33a5fd575e737f74ada3461a6b266ec1bbe5c9933bbb2719b3eac62d7d496c7fb99e15b49
7
+ data.tar.gz: dfc02f84e633cd55fd4131b2459f5749235b4189caf01769d0e3c6fc63b67c2db83c0939c601aee0adebf35c7ac27bea34b07774253fa1b9962fe41c8c40a2aa
data/README.md CHANGED
@@ -1,49 +1,67 @@
1
- # RspecWatcher
1
+ # RSpecWatcher
2
2
 
3
- Automatically runs specs in reaction to changes in files. Loads the project once and uses code reloading to get changes instead of starting a new process for every test run. Needs to be restarted after changes to files that do not get reloaded.
3
+ Provides an instant feedback loop for TDD with RSpec. Automatically runs specs in reaction to changes in files. Inspired by [Guard](https://github.com/guard/guard), but unlike Guard, the watcher does not start a new process every time. It only loads the project once and uses code reloading to get changes. Needs to be restarted after changes to files that do not get reloaded (just like you would restart a Rails development server).
4
4
 
5
- ## Installation
5
+ Specs that fail are remembered and will be rerun until they pass again. This enables a nearly instant TDD feedbeck loop, because every spec we add will be automatically picked up and run until we add the implementation.
6
6
 
7
- Install the gem and add to the application's Gemfile by executing:
7
+ ## Installation
8
8
 
9
- $ bundle add rspec-watcher
9
+ Add `rspec-watcher` to the Gemfile, only needs to exist in the `test` group.
10
10
 
11
- If bundler is not being used to manage dependencies, install the gem by executing:
11
+ ```ruby
12
+ group :test do
13
+ gem 'rspec-watcher'
14
+ end
15
+ ```
12
16
 
13
- $ gem install rspec-watcher
17
+ Then run `bundle install`
14
18
 
15
19
  ## Usage
16
20
 
17
- Start the watcher with `RAILS_ENV=test bundle exec rake rspec_watcher:watch`
21
+ ### Configuration
18
22
 
19
- In order to use the watcher without Rails, `path_inferrer` and `reloader` need to be configured. Check `lib/rspec_watcher.rb`. The rake task also assumes usage inside a Rails project.
23
+ Disable caching classes in `config/environments/test.rb` when the watcher is running:
20
24
 
21
- Configuration can be specified in `config/rspec_watcher.rb`, this is the default:
25
+ ```ruby
26
+ config.cache_classes = ENV['RSPEC_WATCHER'].nil?
27
+ ```
28
+
29
+ Rules for the watcher and other options can be customized, for example in a Rails initializer. Not passing a block to a `watch` rule will run all specs. The configuration shown here is used by default:
22
30
 
23
31
  ```ruby
24
- RSpecWatcher.configure do
25
- watch 'spec', only: /_spec\.rb\z/ do |modified, added, _removed|
26
- modified + added
27
- end
32
+ # config/initializers/rspec_watcher.rb
28
33
 
29
- watch 'spec', ignore: /_spec\.rb\z/
34
+ if ENV['RSPEC_WATCHER']
35
+ RSpecWatcher.configure do
36
+ watch 'spec', only: /_spec\.rb\z/ do |modified, added, _removed|
37
+ modified + added
38
+ end
39
+
40
+ watch 'spec', ignore: /_spec\.rb\z/
30
41
 
31
- watch 'app', only: /\.rb\z/, ignore: %r{controllers/} do |modified, added, removed|
32
- (modified + added + removed).map do |path|
33
- path.sub('app/', 'spec/').sub('.rb', '_spec.rb')
42
+ watch 'app', only: /\.rb\z/, ignore: %r{controllers/} do |modified, added, removed|
43
+ (modified + added + removed).map do |path|
44
+ path.sub('app/', 'spec/').sub('.rb', '_spec.rb')
45
+ end
34
46
  end
35
- end
36
47
 
37
- watch 'app/controllers', only: /\.rb\z/ do |modified, added, removed|
38
- (modified + added + removed).map do |path|
39
- path.sub('app/', 'spec/').sub('controllers/', 'requests/').sub('_controller.rb', '_spec.rb')
48
+ watch 'app/controllers', only: /\.rb\z/ do |modified, added, removed|
49
+ (modified + added + removed).map do |path|
50
+ path.sub('app/', 'spec/').sub('controllers/', 'requests/').sub('_controller.rb', '_spec.rb')
51
+ end
40
52
  end
41
- end
42
53
 
43
- watch 'config', only: /routes\.rb\z/
54
+ watch 'config', only: /routes\.rb\z/
55
+ end
44
56
  end
45
57
  ```
46
58
 
59
+ ### Running the watcher
60
+
61
+ Start the watcher with `RAILS_ENV=test bundle exec rake rspec_watcher:watch`
62
+
63
+ In order to use the watcher without Rails, `path_inferrer` and `reloader` need to be configured. Check `lib/rspec-watcher.rb`.
64
+
47
65
  ## Development
48
66
 
49
67
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/rspec-watcher.rb CHANGED
@@ -10,6 +10,7 @@ module RSpecWatcher
10
10
 
11
11
  @path_inferrer = PATH_INFERRER
12
12
  @reloader = RELOADER
13
+ @rules = []
13
14
 
14
15
  class << self
15
16
  attr_accessor :path_inferrer, :reloader
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :rspec_watcher do
4
- desc 'Start the watcher with configuration from config/rspec_watcher.rb'
4
+ desc 'Start the watcher'
5
5
  task :watch do
6
- abort('Not running in test environment') unless Rails.env.test?
6
+ abort('Not running in test environment') if defined?(Rails) && !Rails.env.test?
7
7
 
8
8
  require 'rspec/core'
9
9
 
10
- config_path = Rails.root.join('config/rspec_watcher').to_s
11
- if File.exist?(config_path)
12
- require config_path
13
- else
10
+ ENV['RSPEC_WATCHER'] = 'true'
11
+
12
+ if RSpecWatcher.rules.empty?
14
13
  require_relative '../default_configuration'
14
+ puts 'Using default configuration'
15
15
  end
16
16
 
17
17
  RSpecWatcher.start
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RSpecWatcher
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matous Vokal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-30 00:00:00.000000000 Z
11
+ date: 2023-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: rspec-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
@@ -42,7 +42,6 @@ files:
42
42
  - lib/rspec_watcher/railtie.rb
43
43
  - lib/rspec_watcher/tasks/watch.rake
44
44
  - lib/rspec_watcher/version.rb
45
- - rspec_watcher.gemspec
46
45
  homepage: https://github.com/Sorc96/rspec-watcher
47
46
  licenses:
48
47
  - MIT
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/rspec_watcher/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "rspec-watcher"
7
- spec.version = RSpecWatcher::VERSION
8
- spec.authors = ["Matous Vokal"]
9
- spec.email = ["matous.vokal@gmail.com"]
10
-
11
- spec.summary = "Instant feedback for awesome TDD experience with RSpec."
12
- spec.description = "Automatically runs specs in reaction to changes in files. Loads the project once and uses code reloading to get changes instead of starting a new process for every test run."
13
- spec.homepage = "https://github.com/Sorc96/rspec-watcher"
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/Sorc96/rspec-watcher"
19
-
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(__dir__) do
23
- `git ls-files -z`.split("\x0").reject do |f|
24
- (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
25
- end
26
- end
27
- spec.require_paths = ["lib"]
28
-
29
- spec.add_dependency "rspec", "~> 3.0"
30
- end