Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support comments in the Gemfile tokenization #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pessimize/gemfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def parse_gems_from_tokens!
end

def all_gem_tokens_collected?(current_token, next_token)
next_token[1] == :on_nl
[:on_nl, :on_comment].include?(next_token[1])
end

class TokenCompiler
Expand Down
16 changes: 16 additions & 0 deletions spec/gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ module Pessimize

end

context "creating a gem with a comment" do
let(:gem) { Gem.new(Ripper.lex('gem "blah" # It blahs')) }
subject { gem }

its(:name) { should == "blah" }

context "after setting the version" do
before do
gem.version = "~> 2.1"
end

its(:to_s) { should == 'gem "blah", "~> 2.1" # It blahs' }
end

end

context "creating a gem using new lines for arguments" do
let(:gem_string) { <<GEM.strip
gem "blah",
Expand Down
64 changes: 64 additions & 0 deletions spec/gemfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,69 @@ module Pessimize
its(:to_s) { should == expected_defn }
end
end

context "with multiple gem definitions separated with comments" do

let(:gem_defn) { <<-GEM
source "https://rubygems.org"

gem "monkey", "2.0.0" # a comment to throw things off

gem "thor", ">= 1.3.0"
GEM
}

subject(:gemfile) { Gemfile.new(gem_defn) }

its(:to_s) { should == gem_defn }

describe "#gems" do
subject(:gems) { gemfile.gems }

its(:length) { should == 2 }

describe "the first gem" do
subject(:gem) { gems[0] }

its(:name) { should == "monkey" }
its(:version) { should == "2.0.0" }
its(:to_s) { should == ' "monkey", "2.0.0" ' }

context "setting the version" do
before do
gem.version = "~> 2.0.0"
end

its(:to_s) { should == ' "monkey", "~> 2.0.0" ' }
end
end

describe "the second gem" do
subject { gems[1] }

its(:name) { should == "thor" }
its(:version) { should == ">= 1.3.0" }
end
end

context "after setting the gem versions" do
before do
gemfile.gems.each do |gem|
gem.version = "~> 1.0.0"
end
end

let(:expected_defn) { <<-GEM
source "https://rubygems.org"

gem "monkey", "~> 1.0.0" # a comment to throw things off

gem "thor", "~> 1.0.0"
GEM
}

its(:to_s) { should == expected_defn }
end
end
end
end