Skip to content

Commit

Permalink
Update Gemfile Parser
Browse files Browse the repository at this point in the history
Allow parsing with and without spaces when trying to find the `puma`
gem.

Signed-off-by: Jon Whitcraft <[email protected]>
  • Loading branch information
jwhitcraft authored and sophiewigmore committed Oct 11, 2021
1 parent 6936689 commit bdfe6f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gemfile_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (p GemfileParser) Parse(path string) (bool, error) {
defer file.Close()

quotes := `["']`
pumaRe := regexp.MustCompile(fmt.Sprintf(`gem %spuma%s`, quotes, quotes))
pumaRe := regexp.MustCompile(fmt.Sprintf(`^\s*gem %spuma%s`, quotes, quotes))
scanner := bufio.NewScanner(file)

for scanner.Scan() {
Expand Down
16 changes: 15 additions & 1 deletion gemfile_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,21 @@ func testGemfileParser(t *testing.T, context spec.G, it spec.S) {

context("Parse", func() {
context("when using puma", func() {
it("parses correctly", func() {
it("parses correctly without spaces", func() {
const GEMFILE_CONTENTS = `
source 'https://rubygems.org'
gem 'puma'
`

Expect(ioutil.WriteFile(path, []byte(GEMFILE_CONTENTS), 0644)).To(Succeed())

hasPuma, err := parser.Parse(path)
Expect(err).NotTo(HaveOccurred())
Expect(hasPuma).To(Equal(true))
})

it("parses correctly with spaces", func() {
const GEMFILE_CONTENTS = `
source 'https://rubygems.org' do
gem 'puma'
Expand Down

0 comments on commit bdfe6f6

Please sign in to comment.