Skip to content

Commit

Permalink
Fix tests in master
Browse files Browse the repository at this point in the history
This should only pass tests once
simplecov-ruby/simplecov#747 is merged and
incorporated into a new SimpleCov release.

Fixes #238
  • Loading branch information
JacobEvelyn committed Sep 24, 2019
1 parent f0a44f4 commit dd90286
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 66 deletions.
1 change: 1 addition & 0 deletions bin/friends
Expand Up @@ -3,6 +3,7 @@

if ENV["TRAVIS"] == "true" && ENV["CODE_COVERAGE"] == "true"
require "simplecov"
SimpleCov.print_error_status = false
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
SimpleCov.command_name Process.pid.to_s
SimpleCov.start
Expand Down
2 changes: 1 addition & 1 deletion friends.gemspec
Expand Up @@ -38,5 +38,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest", "~> 5.5"
spec.add_development_dependency "minitest-proveit", "~> 1.0"
spec.add_development_dependency "rake", "~> 12.3"
spec.add_development_dependency "simplecov", "~> 0.14"
spec.add_development_dependency "simplecov", "~> 0.17"
end
2 changes: 1 addition & 1 deletion test/add_event_helper.rb
Expand Up @@ -56,7 +56,7 @@ def description_parsing_specs(test_stdout: true)
let(:description) { " " }

it "prints an error message" do
subject[:stderr].must_equal(
value(subject[:stderr]).must_equal(
ensure_trailing_newline_unless_empty("Error: Blank #{event} not added")
)
end
Expand Down
2 changes: 1 addition & 1 deletion test/commands/add/activity_spec.rb
Expand Up @@ -32,7 +32,7 @@

it "orders dates by insertion time" do
subject
File.read(filename).must_equal <<-FILE
value(File.read(filename)).must_equal <<-FILE
### Activities:
- 2018-01-01: Activity one year later.
- 2017-01-01: Activity 5.
Expand Down
2 changes: 1 addition & 1 deletion test/commands/add/note_spec.rb
Expand Up @@ -32,7 +32,7 @@

it "orders dates by insertion time" do
subject
File.read(filename).must_equal <<-FILE
value(File.read(filename)).must_equal <<-FILE
### Activities:
### Notes:
Expand Down
2 changes: 1 addition & 1 deletion test/commands/clean_spec.rb
Expand Up @@ -15,7 +15,7 @@
let(:content) { nil }

it "does not create the file" do
File.exist?(filename).must_equal false
value(File.exist?(filename)).must_equal false
end
end

Expand Down
36 changes: 20 additions & 16 deletions test/commands/help_spec.rb
Expand Up @@ -8,29 +8,33 @@

describe "with no subcommand passed" do
it "prints overall help message" do
subject[:stderr].must_equal ""
subject[:status].must_equal 0
[
"NAME",
"SYNOPSIS",
"VERSION",
"GLOBAL OPTIONS",
"COMMANDS"
].all? { |msg| subject[:stdout].include? msg }.must_equal true
value(subject[:stderr]).must_equal ""
value(subject[:status]).must_equal 0
value(
[
"NAME",
"SYNOPSIS",
"VERSION",
"GLOBAL OPTIONS",
"COMMANDS"
].all? { |msg| subject[:stdout].include? msg }
).must_equal true
end
end

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

it "prints subcommand help message" do
subject[:stderr].must_equal ""
subject[:status].must_equal 0
[
"NAME",
"SYNOPSIS",
"COMMAND OPTIONS"
].all? { |msg| subject[:stdout].include? msg }.must_equal true
value(subject[:stderr]).must_equal ""
value(subject[:status]).must_equal 0
value(
[
"NAME",
"SYNOPSIS",
"COMMAND OPTIONS"
].all? { |msg| subject[:stdout].include? msg }
).must_equal true
end
end

Expand Down
24 changes: 12 additions & 12 deletions test/commands/list/favorite/friends_spec.rb
Expand Up @@ -79,34 +79,34 @@
end

it "uses tied ranks" do
subject[:stderr].must_equal ""
subject[:status].must_equal 0
value(subject[:stderr]).must_equal ""
value(subject[:status]).must_equal 0

lines = subject[:stdout].split("\n")
lines[1].must_match(/1\. Friend (A|B)/)
lines[2].must_match(/1\. Friend (A|B)/)
lines[3].must_include "3. Friend"
value(lines[1]).must_match(/1\. Friend (A|B)/)
value(lines[2]).must_match(/1\. Friend (A|B)/)
value(lines[3]).must_include "3. Friend"
end

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

lines = subject[:stdout].split("\n")
lines[1].must_include "activities"
lines[2].wont_include "activities"
value(lines[1]).must_include "activities"
value(lines[2]).wont_include "activities"
end

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

# Since there are 10 friends, a naive implementation would pad our output
# assuming the (numerically) highest rank is "10." but since the highest
# rank is a tie, we never display a double-digit rank, so we don't need to
# pad our output for double digits.
lines = subject[:stdout].split("\n")
lines.last.must_include "3. Friend"
value(lines.last).must_include "3. Friend"
end
end
end
Expand Down
24 changes: 12 additions & 12 deletions test/commands/list/favorite/locations_spec.rb
Expand Up @@ -84,34 +84,34 @@
end

it "uses tied ranks" do
subject[:stderr].must_equal ""
subject[:status].must_equal 0
value(subject[:stderr]).must_equal ""
value(subject[:status]).must_equal 0

lines = subject[:stdout].split("\n")
lines[1].must_match(/1\. Location (A|B)/)
lines[2].must_match(/1\. Location (A|B)/)
lines[3].must_include "3. Location"
value(lines[1]).must_match(/1\. Location (A|B)/)
value(lines[2]).must_match(/1\. Location (A|B)/)
value(lines[3]).must_include "3. Location"
end

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

lines = subject[:stdout].split("\n")
lines[1].must_include "activities"
lines[2].wont_include "activities"
value(lines[1]).must_include "activities"
value(lines[2]).wont_include "activities"
end

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

# Since there are 10 friends, a naive implementation would pad our output
# assuming the (numerically) highest rank is "10." but since the highest
# rank is a tie, we never display a double-digit rank, so we don't need to
# pad our output for double digits.
lines = subject[:stdout].split("\n")
lines.last.must_include "3. Location"
value(lines.last).must_include "3. Location"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/commands/rename/friend_spec.rb
Expand Up @@ -33,15 +33,15 @@
end

it "updates friend name in activities" do
run_cmd("list activities")[:stdout].must_equal <<-FILE
value(run_cmd("list activities")[:stdout]).must_equal <<-FILE
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.
2015-11-01: Grace Hopper and I went to Marie's Diner. George had to cancel at the last minute. @food
2015-01-04: Got lunch with Grace Hopper and George Washington Carver. @food
2014-12-31: Celebrated the new year in Paris with Marie Curie. @partying
2014-11-15: Talked to George Washington Carver on the phone for an hour.
FILE
subject
run_cmd("list activities")[:stdout].must_equal <<-FILE
value(run_cmd("list activities")[:stdout]).must_equal <<-FILE
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.
2015-11-01: Grace Hopper and I went to Marie's Diner. George had to cancel at the last minute. @food
2015-01-04: Got lunch with Grace Hopper and George Washington. @food
Expand Down
14 changes: 8 additions & 6 deletions test/commands/update_spec.rb
Expand Up @@ -7,14 +7,16 @@
let(:content) { nil }

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

it "prints the post-install message" do
subject[:stderr].must_equal ""
subject[:status].must_equal 0
subject[:stdout].must_include Friends::POST_INSTALL_MESSAGE
value(subject[:stderr]).must_equal ""
value(subject[:status]).must_equal 0
value(subject[:stdout]).must_include Friends::POST_INSTALL_MESSAGE
end
end
4 changes: 2 additions & 2 deletions test/default_file_spec.rb
Expand Up @@ -18,14 +18,14 @@
# https://github.com/JacobEvelyn/friends/issues/231
it "creates a new file and adds to it multiple times" do
# File does not exist at first.
File.exist?(filename).must_equal false
value(File.exist?(filename)).must_equal false

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

File.read(filename).must_equal <<-FILE
value(File.read(filename)).must_equal <<-FILE
### Activities:
- 1859-11-30: Lunch with **Harriet Tubman** in _Auburn_.
Expand Down
22 changes: 11 additions & 11 deletions test/helper.rb
Expand Up @@ -108,35 +108,35 @@ def ensure_trailing_newline_unless_empty(str)

def stdout_only(expected)
puts subject[:stderr] unless subject[:stderr] == ""
subject[:stdout].must_equal ensure_trailing_newline_unless_empty(expected)
subject[:stderr].must_equal ""
subject[:status].must_equal 0
value(subject[:stdout]).must_equal ensure_trailing_newline_unless_empty(expected)
value(subject[:stderr]).must_equal ""
value(subject[:status]).must_equal 0
end

def stderr_only(expected)
subject[:stdout].must_equal ""
subject[:stderr].must_equal ensure_trailing_newline_unless_empty(expected)
subject[:status].must_be :>, 0
value(subject[:stdout]).must_equal ""
value(subject[:stderr]).must_equal ensure_trailing_newline_unless_empty(expected)
value(subject[:status]).must_be :>, 0
end

def file_equals(expected)
subject
File.read(filename).must_equal expected
value(File.read(filename)).must_equal expected
end

def line_changed(expected_old, expected_new)
index = File.read(filename).split("\n").index(expected_old)
index.must_be_kind_of Numeric # Not nil, so we know that `expected_old` was found.
value(index).must_be_kind_of Numeric # Not nil, so we know that `expected_old` was found.
subject
File.read(filename).split("\n")[index].must_equal expected_new
value(File.read(filename).split("\n")[index]).must_equal expected_new
end

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

def clean_describe(desc, &block)
Expand Down

0 comments on commit dd90286

Please sign in to comment.