Skip to content

Commit

Permalink
Separate optional test dependencies with Gemfiles
Browse files Browse the repository at this point in the history
This commit adds a `Gemfile.old` which is used for testing
old Ruby versions in Travis. This file does not include
dependencies such as Rubocop and SimpleCov that are only
used in either local development or our Travis build for
the latest Ruby version.

Included in these changes is pinning the SimpleCov dependency
to the version fixed by
simplecov-ruby/simplecov#747 to fix tests.

[@shen-sat](https://github.com/shen-sat) was instrumental in
discussing these changes and coming up with many parts of
the overall approach. Many thanks!

Fixes #238
  • Loading branch information
JacobEvelyn committed Oct 3, 2019
1 parent f0a44f4 commit e0e81e0
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -5,11 +5,13 @@ rvm:
- 2.3
- 2.4
- 2.5 # 2.6 is tested below
gemfile: Gemfile.old # The latest Ruby version uses Gemfile below
script:
- bundle exec rake test
matrix:
include:
- rvm: 2.6
gemfile: Gemfile
script:
- bundle exec rake test
- gem install --no-document rubocop -v 0.67 && rubocop
Expand Down
11 changes: 11 additions & 0 deletions Gemfile
Expand Up @@ -3,3 +3,14 @@
source "https://rubygems.org"

gemspec

group :development, :test do
gem "rubocop", "0.67"
end

group :test do
gem "codecov", "~> 0.1.14"
gem "simplecov",
git: "https://github.com/colszowka/simplecov",
ref: "cb968abf857a704364283b5dec4d9fa3d096287e"
end
5 changes: 5 additions & 0 deletions Gemfile.old
@@ -0,0 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec
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
3 changes: 0 additions & 3 deletions friends.gemspec
Expand Up @@ -33,10 +33,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "semverse", ">= 2", "< 4"
spec.add_dependency "tty-pager", "~> 0.11"

spec.add_development_dependency "bundler", ">= 1.6"
spec.add_development_dependency "codecov", "~> 0.1.14"
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"
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 e0e81e0

Please sign in to comment.