Skip to content

Commit a1cb48f

Browse files
authored
Merge pull request #239 from JacobEvelyn/fix-tests
Separate optional test dependencies with Gemfiles
2 parents f0a44f4 + e0e81e0 commit a1cb48f

16 files changed

+90
-68
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ rvm:
55
- 2.3
66
- 2.4
77
- 2.5 # 2.6 is tested below
8+
gemfile: Gemfile.old # The latest Ruby version uses Gemfile below
89
script:
910
- bundle exec rake test
1011
matrix:
1112
include:
1213
- rvm: 2.6
14+
gemfile: Gemfile
1315
script:
1416
- bundle exec rake test
1517
- gem install --no-document rubocop -v 0.67 && rubocop

Gemfile

+11
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,14 @@
33
source "https://rubygems.org"
44

55
gemspec
6+
7+
group :development, :test do
8+
gem "rubocop", "0.67"
9+
end
10+
11+
group :test do
12+
gem "codecov", "~> 0.1.14"
13+
gem "simplecov",
14+
git: "https://github.com/colszowka/simplecov",
15+
ref: "cb968abf857a704364283b5dec4d9fa3d096287e"
16+
end

Gemfile.old

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gemspec

bin/friends

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
if ENV["TRAVIS"] == "true" && ENV["CODE_COVERAGE"] == "true"
55
require "simplecov"
6+
SimpleCov.print_error_status = false
67
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
78
SimpleCov.command_name Process.pid.to_s
89
SimpleCov.start

friends.gemspec

-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ Gem::Specification.new do |spec|
3333
spec.add_dependency "semverse", ">= 2", "< 4"
3434
spec.add_dependency "tty-pager", "~> 0.11"
3535

36-
spec.add_development_dependency "bundler", ">= 1.6"
37-
spec.add_development_dependency "codecov", "~> 0.1.14"
3836
spec.add_development_dependency "minitest", "~> 5.5"
3937
spec.add_development_dependency "minitest-proveit", "~> 1.0"
4038
spec.add_development_dependency "rake", "~> 12.3"
41-
spec.add_development_dependency "simplecov", "~> 0.14"
4239
end

test/add_event_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def description_parsing_specs(test_stdout: true)
5656
let(:description) { " " }
5757

5858
it "prints an error message" do
59-
subject[:stderr].must_equal(
59+
value(subject[:stderr]).must_equal(
6060
ensure_trailing_newline_unless_empty("Error: Blank #{event} not added")
6161
)
6262
end

test/commands/add/activity_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
it "orders dates by insertion time" do
3434
subject
35-
File.read(filename).must_equal <<-FILE
35+
value(File.read(filename)).must_equal <<-FILE
3636
### Activities:
3737
- 2018-01-01: Activity one year later.
3838
- 2017-01-01: Activity 5.

test/commands/add/note_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
it "orders dates by insertion time" do
3434
subject
35-
File.read(filename).must_equal <<-FILE
35+
value(File.read(filename)).must_equal <<-FILE
3636
### Activities:
3737
3838
### Notes:

test/commands/clean_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
let(:content) { nil }
1616

1717
it "does not create the file" do
18-
File.exist?(filename).must_equal false
18+
value(File.exist?(filename)).must_equal false
1919
end
2020
end
2121

test/commands/help_spec.rb

+20-16
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,33 @@
88

99
describe "with no subcommand passed" do
1010
it "prints overall help message" do
11-
subject[:stderr].must_equal ""
12-
subject[:status].must_equal 0
13-
[
14-
"NAME",
15-
"SYNOPSIS",
16-
"VERSION",
17-
"GLOBAL OPTIONS",
18-
"COMMANDS"
19-
].all? { |msg| subject[:stdout].include? msg }.must_equal true
11+
value(subject[:stderr]).must_equal ""
12+
value(subject[:status]).must_equal 0
13+
value(
14+
[
15+
"NAME",
16+
"SYNOPSIS",
17+
"VERSION",
18+
"GLOBAL OPTIONS",
19+
"COMMANDS"
20+
].all? { |msg| subject[:stdout].include? msg }
21+
).must_equal true
2022
end
2123
end
2224

2325
describe "with a subcommand passed" do
2426
subject { run_cmd("help graph") }
2527

2628
it "prints subcommand help message" do
27-
subject[:stderr].must_equal ""
28-
subject[:status].must_equal 0
29-
[
30-
"NAME",
31-
"SYNOPSIS",
32-
"COMMAND OPTIONS"
33-
].all? { |msg| subject[:stdout].include? msg }.must_equal true
29+
value(subject[:stderr]).must_equal ""
30+
value(subject[:status]).must_equal 0
31+
value(
32+
[
33+
"NAME",
34+
"SYNOPSIS",
35+
"COMMAND OPTIONS"
36+
].all? { |msg| subject[:stdout].include? msg }
37+
).must_equal true
3438
end
3539
end
3640

test/commands/list/favorite/friends_spec.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -79,34 +79,34 @@
7979
end
8080

8181
it "uses tied ranks" do
82-
subject[:stderr].must_equal ""
83-
subject[:status].must_equal 0
82+
value(subject[:stderr]).must_equal ""
83+
value(subject[:status]).must_equal 0
8484

8585
lines = subject[:stdout].split("\n")
86-
lines[1].must_match(/1\. Friend (A|B)/)
87-
lines[2].must_match(/1\. Friend (A|B)/)
88-
lines[3].must_include "3. Friend"
86+
value(lines[1]).must_match(/1\. Friend (A|B)/)
87+
value(lines[2]).must_match(/1\. Friend (A|B)/)
88+
value(lines[3]).must_include "3. Friend"
8989
end
9090

9191
it "only uses the word 'activities' for the first item, even when a tie" do
92-
subject[:stderr].must_equal ""
93-
subject[:status].must_equal 0
92+
value(subject[:stderr]).must_equal ""
93+
value(subject[:status]).must_equal 0
9494

9595
lines = subject[:stdout].split("\n")
96-
lines[1].must_include "activities"
97-
lines[2].wont_include "activities"
96+
value(lines[1]).must_include "activities"
97+
value(lines[2]).wont_include "activities"
9898
end
9999

100100
it "indents based on the highest rank number, not the number of friends" do
101-
subject[:stderr].must_equal ""
102-
subject[:status].must_equal 0
101+
value(subject[:stderr]).must_equal ""
102+
value(subject[:status]).must_equal 0
103103

104104
# Since there are 10 friends, a naive implementation would pad our output
105105
# assuming the (numerically) highest rank is "10." but since the highest
106106
# rank is a tie, we never display a double-digit rank, so we don't need to
107107
# pad our output for double digits.
108108
lines = subject[:stdout].split("\n")
109-
lines.last.must_include "3. Friend"
109+
value(lines.last).must_include "3. Friend"
110110
end
111111
end
112112
end

test/commands/list/favorite/locations_spec.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -84,34 +84,34 @@
8484
end
8585

8686
it "uses tied ranks" do
87-
subject[:stderr].must_equal ""
88-
subject[:status].must_equal 0
87+
value(subject[:stderr]).must_equal ""
88+
value(subject[:status]).must_equal 0
8989

9090
lines = subject[:stdout].split("\n")
91-
lines[1].must_match(/1\. Location (A|B)/)
92-
lines[2].must_match(/1\. Location (A|B)/)
93-
lines[3].must_include "3. Location"
91+
value(lines[1]).must_match(/1\. Location (A|B)/)
92+
value(lines[2]).must_match(/1\. Location (A|B)/)
93+
value(lines[3]).must_include "3. Location"
9494
end
9595

9696
it "only uses the word 'activities' for the first item, even when a tie" do
97-
subject[:stderr].must_equal ""
98-
subject[:status].must_equal 0
97+
value(subject[:stderr]).must_equal ""
98+
value(subject[:status]).must_equal 0
9999

100100
lines = subject[:stdout].split("\n")
101-
lines[1].must_include "activities"
102-
lines[2].wont_include "activities"
101+
value(lines[1]).must_include "activities"
102+
value(lines[2]).wont_include "activities"
103103
end
104104

105105
it "indents based on the highest rank number, not the number of locations" do
106-
subject[:stderr].must_equal ""
107-
subject[:status].must_equal 0
106+
value(subject[:stderr]).must_equal ""
107+
value(subject[:status]).must_equal 0
108108

109109
# Since there are 10 friends, a naive implementation would pad our output
110110
# assuming the (numerically) highest rank is "10." but since the highest
111111
# rank is a tie, we never display a double-digit rank, so we don't need to
112112
# pad our output for double digits.
113113
lines = subject[:stdout].split("\n")
114-
lines.last.must_include "3. Location"
114+
value(lines.last).must_include "3. Location"
115115
end
116116
end
117117
end

test/commands/rename/friend_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
end
3434

3535
it "updates friend name in activities" do
36-
run_cmd("list activities")[:stdout].must_equal <<-FILE
36+
value(run_cmd("list activities")[:stdout]).must_equal <<-FILE
3737
2018-02-06: @science:indoors:agronomy-with-hydroponics: Norman Borlaug and George Washington Carver scored a tour of Atlantis' hydroponics gardens through wetplants@example.org and they took me along.
3838
2015-11-01: Grace Hopper and I went to Marie's Diner. George had to cancel at the last minute. @food
3939
2015-01-04: Got lunch with Grace Hopper and George Washington Carver. @food
4040
2014-12-31: Celebrated the new year in Paris with Marie Curie. @partying
4141
2014-11-15: Talked to George Washington Carver on the phone for an hour.
4242
FILE
4343
subject
44-
run_cmd("list activities")[:stdout].must_equal <<-FILE
44+
value(run_cmd("list activities")[:stdout]).must_equal <<-FILE
4545
2018-02-06: @science:indoors:agronomy-with-hydroponics: Norman Borlaug and George Washington scored a tour of Atlantis' hydroponics gardens through wetplants@example.org and they took me along.
4646
2015-11-01: Grace Hopper and I went to Marie's Diner. George had to cancel at the last minute. @food
4747
2015-01-04: Got lunch with Grace Hopper and George Washington. @food

test/commands/update_spec.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
let(:content) { nil }
88

99
it "prints a status message" do
10-
subject[:stderr].must_equal ""
11-
subject[:status].must_equal 0
12-
[/Updated to friends/, /Already up-to-date/].one? { |m| subject[:stdout] =~ m }.must_equal true
10+
value(subject[:stderr]).must_equal ""
11+
value(subject[:status]).must_equal 0
12+
value(
13+
[/Updated to friends/, /Already up-to-date/].one? { |m| subject[:stdout] =~ m }
14+
).must_equal true
1315
end
1416

1517
it "prints the post-install message" do
16-
subject[:stderr].must_equal ""
17-
subject[:status].must_equal 0
18-
subject[:stdout].must_include Friends::POST_INSTALL_MESSAGE
18+
value(subject[:stderr]).must_equal ""
19+
value(subject[:status]).must_equal 0
20+
value(subject[:stdout]).must_include Friends::POST_INSTALL_MESSAGE
1921
end
2022
end

test/default_file_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
# https://github.com/JacobEvelyn/friends/issues/231
1919
it "creates a new file and adds to it multiple times" do
2020
# File does not exist at first.
21-
File.exist?(filename).must_equal false
21+
value(File.exist?(filename)).must_equal false
2222

2323
`bundle exec bin/friends add friend Mohandas Karamchand Gandhi`
2424
`bundle exec bin/friends add friend Sojourner Truth`
2525
`bundle exec bin/friends add activity 1859-11-30: Lunch with **Harriet Tubman** in _Auburn_.`
2626
`bundle exec bin/friends add note "1851-05-29: Sojourner Truth's speech"`
2727

28-
File.read(filename).must_equal <<-FILE
28+
value(File.read(filename)).must_equal <<-FILE
2929
### Activities:
3030
- 1859-11-30: Lunch with **Harriet Tubman** in _Auburn_.
3131

test/helper.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -108,35 +108,35 @@ def ensure_trailing_newline_unless_empty(str)
108108

109109
def stdout_only(expected)
110110
puts subject[:stderr] unless subject[:stderr] == ""
111-
subject[:stdout].must_equal ensure_trailing_newline_unless_empty(expected)
112-
subject[:stderr].must_equal ""
113-
subject[:status].must_equal 0
111+
value(subject[:stdout]).must_equal ensure_trailing_newline_unless_empty(expected)
112+
value(subject[:stderr]).must_equal ""
113+
value(subject[:status]).must_equal 0
114114
end
115115

116116
def stderr_only(expected)
117-
subject[:stdout].must_equal ""
118-
subject[:stderr].must_equal ensure_trailing_newline_unless_empty(expected)
119-
subject[:status].must_be :>, 0
117+
value(subject[:stdout]).must_equal ""
118+
value(subject[:stderr]).must_equal ensure_trailing_newline_unless_empty(expected)
119+
value(subject[:status]).must_be :>, 0
120120
end
121121

122122
def file_equals(expected)
123123
subject
124-
File.read(filename).must_equal expected
124+
value(File.read(filename)).must_equal expected
125125
end
126126

127127
def line_changed(expected_old, expected_new)
128128
index = File.read(filename).split("\n").index(expected_old)
129-
index.must_be_kind_of Numeric # Not nil, so we know that `expected_old` was found.
129+
value(index).must_be_kind_of Numeric # Not nil, so we know that `expected_old` was found.
130130
subject
131-
File.read(filename).split("\n")[index].must_equal expected_new
131+
value(File.read(filename).split("\n")[index]).must_equal expected_new
132132
end
133133

134134
def line_added(expected)
135135
n_initial_lines = File.read(filename).split("\n").size
136136
subject
137137
lines = File.read(filename).split("\n")
138-
lines.index(expected).must_be_kind_of Numeric # Not nil, so we know that `expected` was found.
139-
lines.size.must_equal(n_initial_lines + 1) # Line was added, not changed.
138+
value(lines.index(expected)).must_be_kind_of Numeric # Not nil, so we know `expected` was found.
139+
value(lines.size).must_equal(n_initial_lines + 1) # Line was added, not changed.
140140
end
141141

142142
def clean_describe(desc, &block)

0 commit comments

Comments
 (0)