devloop 0.1.2 → 0.1.4

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: 1aacef492d0bf184908275bc5df40ba6915cf3a1215edc39fb41374fa18574e0
4
- data.tar.gz: aa92fd7489fcd1fbefaf1ad01e7fddcf9b39b8ab9ba9d9964794ba15cba15559
3
+ metadata.gz: 41dcab2a2c737d831c773f69df17a5b3f940bf3afd17a7b28aa43d0d2babff28
4
+ data.tar.gz: 959cab9d951a675abead4c652b2265140b32536d76bd69beaaf123fd5d06a06e
5
5
  SHA512:
6
- metadata.gz: a26d307a8957fba390304bdcacbb6e3b2b23c4f86bb3fcbbc9b3a2fc0e14b69a16836cf7f4cb9e6b68efcc24a775113bdc5b64b639c0da3921ab9f2a835f006e
7
- data.tar.gz: 4444e6eede7525a922044f6c2f7c7d1363b5d9490d94dce08499b52d2021338d04acdb1a95eaf3dfc43fed50edfd2a800a006a3b4d8701dcb152c1caa9e958dc
6
+ metadata.gz: 185b68859cb4a1b50f0b532a63922f9ada0cbae2b14cfb0f39c5ae045f10adeac219a15e11bc71a483b91e40b458146c42cd3c53da61b4094506db71a7f488f8
7
+ data.tar.gz: 7d1f59eff8df744568ad744d5812749e543d41ef4156eeb9d87bdc7afa47b84866b16be469aea3fb4dff6140c860690cc7f804966fc8ec7567ab2c2847959323
data/bin/devloop CHANGED
@@ -3,9 +3,14 @@
3
3
  $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib") unless $LOAD_PATH.include?(File.dirname(__FILE__) + "/../lib")
4
4
 
5
5
  require "devloop"
6
+ require "devloop/version"
6
7
  require "listen"
7
8
 
8
9
  begin
10
+ if %w[--version -v].include?(ARGV[0])
11
+ puts "Devloop version #{Devloop::VERSION}"
12
+ end
13
+
9
14
  system("bundle exec spring > /dev/null 2>&1")
10
15
  is_bundled = `bundle list`.include?("devloop")
11
16
  run_command = is_bundled ? "bundle exec devloop_run" : "devloop_run"
@@ -4,30 +4,35 @@ module Devloop
4
4
  new.call(diff)
5
5
  end
6
6
 
7
+ Diff = Struct.new(:filename, :line_number)
8
+
7
9
  def call(diff)
8
- _, results = diff.split("\n").reduce(["", []]) do |(file, results), line|
10
+ _, diffs_data = diff.split("\n").reduce(["", []]) do |(file, diffs_data), line|
9
11
  if line.start_with?("+++ b/")
10
- [line[6..-1], results]
12
+ [line[6..-1], diffs_data]
11
13
  elsif line.start_with?("@@ -")
12
14
  line_number = line.match(/@@ -(\d+)/)[1]
13
- if line_number == "1"
14
- [file, results << "#{relative_path(file)}"]
15
- else
16
- [file, results << "#{relative_path(file)}:#{line_number}"]
17
- end
15
+ [file, diffs_data << Diff.new(relative_path(file), line_number)]
18
16
  else
19
- [file, results]
17
+ [file, diffs_data]
20
18
  end
21
19
  end.uniq
22
20
 
23
- # Remove filenames with line number if filename without line number is present
24
- res = results.reject { |result| results.include?(result.split(":").first) && result.include?(":") }.map do |el|
25
- if el.split(":").last == "0"
26
- el.split(":").first
21
+ results = diffs_data.group_by do |el|
22
+ el.filename
23
+ end.map do |key, value|
24
+ line_numbers = value.map(&:line_number).map(&:to_i)
25
+ if line_numbers.include?(0) || line_numbers.include?(1)
26
+ key
27
27
  else
28
- el
28
+ lines_range = (line_numbers.min..line_numbers.max).to_a.join(":")
29
+
30
+ "#{key}:#{lines_range}"
29
31
  end
30
32
  end
33
+
34
+ # Remove filenames with line number if filename without line number is present
35
+ res = results.reject { |result| results.include?(result.split(":").first) && result.include?(":") }
31
36
  end
32
37
 
33
38
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Devloop
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -68,7 +68,7 @@ describe Devloop::DiffParser do
68
68
 
69
69
  it "parses the diff correctly" do
70
70
  expect(Devloop::DiffParser.call(diff1)).to eq(["spec/models/team_spec.rb:10", "spec/models/user_spec.rb:167"])
71
- expect(Devloop::DiffParser.call(diff2)).to eq(["spec/models/team_spec.rb:19", "spec/models/team_spec.rb:24"])
71
+ expect(Devloop::DiffParser.call(diff2)).to eq(["spec/models/team_spec.rb:19:20:21:22:23:24"])
72
72
  end
73
73
  end
74
74
 
@@ -93,7 +93,7 @@ describe Devloop::DiffParser do
93
93
  it "parses the diff correctly" do
94
94
  allow_any_instance_of(Devloop::DiffParser).to receive(:git_root_path).and_return("/Users/username/projects/")
95
95
  allow_any_instance_of(Devloop::DiffParser).to receive(:project_path).and_return("src/")
96
- expect(Devloop::DiffParser.call(diff)).to eq(["spec/models/team_spec.rb:19", "spec/models/team_spec.rb:24"])
96
+ expect(Devloop::DiffParser.call(diff)).to eq(["spec/models/team_spec.rb:19:20:21:22:23:24"])
97
97
  end
98
98
  end
99
99
 
@@ -142,7 +142,37 @@ describe Devloop::DiffParser do
142
142
  end
143
143
 
144
144
  it "parses the diff correctly" do
145
- expect(Devloop::DiffParser.call(diff)).to eq(["spec/config_spec.rb:5", "spec/config_spec.rb:8", "spec/config_spec.rb:14", "spec/config_spec.rb:17", "spec/default_notifier_spec.rb"])
145
+ expect(Devloop::DiffParser.call(diff)).to eq(["spec/config_spec.rb:5:6:7:8:9:10:11:12:13:14:15:16:17", "spec/default_notifier_spec.rb"])
146
+ end
147
+ end
148
+
149
+ context "executes each matching spec" do
150
+ let(:diff) do
151
+ <<~DIFF
152
+ diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
153
+ index 410ffa8c..0266ea38 100644
154
+ --- a/spec/models/user_spec.rb
155
+ +++ b/spec/models/user_spec.rb
156
+ @@ -10,3 +10,3 @@ describe User do
157
+ - it "has a valid factory" do
158
+ - expect(user).to be_valid
159
+ - end
160
+ + it "has a valid factory" do #
161
+ + expect(user).to be_valid #
162
+ + end #
163
+ @@ -14,2 +14,2 @@ describe User do
164
+ - it "has pending_feedbacks" do
165
+ - expect(create(:user).pending_feedbacks).to eq []
166
+ + it "has pending_feedbacks" do#
167
+ + expect(create(:user).pending_feedbacks).to eq [] #
168
+ @@ -17 +17 @@ describe User do
169
+ -
170
+ +#
171
+ DIFF
172
+ end
173
+
174
+ it "parses the diff correctly" do
175
+ expect(Devloop::DiffParser.call(diff)).to eq(["spec/models/user_spec.rb:10:11:12:13:14:15:16:17"])
146
176
  end
147
177
  end
148
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devloop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-26 00:00:00.000000000 Z
11
+ date: 2024-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: listen