Skip to content

Commit

Permalink
Avoid using StringScanner#captures, not available before Ruby 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pgeraghty committed Sep 24, 2019
1 parent ec4d4ae commit 6ade861
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ansible/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.to_html(line, stream='')
s = StringScanner.new(ERB::Util.h line)
while(!s.eos?)
if s.scan(/\e\[([0-1])?[;]?(3[0-7]|90|1)m/)
bold, colour = s.captures
bold, colour = s[1], s[2]
styles = []

styles << COLOR[bold] if bold.to_i == 1
Expand Down
3 changes: 2 additions & 1 deletion spec/ansible/output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ module Output
it 'handles situations where no style attribute should be added to the tag' do
output = "\e[0;99Nothing\e[0m"

s = instance_double("StringScanner", captures: [])
s = instance_double("StringScanner")
allow(s).to receive(:eos?).and_return(false, true)
allow(s).to receive(:scan).and_return(true, '')
allow(s).to receive(:[]).and_return(nil, nil)

class_double("StringScanner", new: s).as_stubbed_const

Expand Down

0 comments on commit 6ade861

Please sign in to comment.