Skip to content

Commit

Permalink
remove private attributes that causes warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Nov 16, 2013
1 parent dbbbd72 commit 29a618f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
18 changes: 8 additions & 10 deletions lib/rspec/expectations/diff_presenter.rb
Expand Up @@ -10,10 +10,10 @@ class DiffPresenter
def diff_as_string(actual, expected)
@encoding = pick_encoding actual, expected

@actual = EncodedString.new(actual, encoding)
@expected = EncodedString.new(expected, encoding)
@actual = EncodedString.new(actual, @encoding)
@expected = EncodedString.new(expected, @encoding)

output = EncodedString.new("\n", encoding)
output = EncodedString.new("\n", @encoding)

hunks.each_cons(2) do |prev_hunk, current_hunk|
begin
Expand Down Expand Up @@ -44,9 +44,7 @@ def diff_as_object(actual, expected)
end
end

private

attr_reader :expected, :actual, :encoding
private

def hunks
@hunks ||= Differ.new(@actual, @expected).hunks
Expand Down Expand Up @@ -128,11 +126,11 @@ def pick_encoding(source_a, source_b)
end

def handle_encoding_errors
if actual.encoding != expected.encoding
"Could not produce a diff because the encoding of the actual string (#{actual.encoding}) "+
"differs from the encoding of the expected string (#{expected.encoding})"
if @actual.encoding != @expected.encoding
"Could not produce a diff because the encoding of the actual string (#{@actual.encoding}) "+
"differs from the encoding of the expected string (#{@expected.encoding})"
else
"Could not produce a diff because of the encoding of the string (#{expected.encoding})"
"Could not produce a diff because of the encoding of the string (#{@expected.encoding})"
end
end
end
Expand Down
7 changes: 3 additions & 4 deletions lib/rspec/expectations/differ.rb
Expand Up @@ -11,18 +11,18 @@ def hunks
end
end

private
private

def diffs
Diff::LCS.diff(expected_lines, actual_lines)
end

def expected_lines
expected.split("\n").map! { |e| e.chomp }
@expected.split("\n").map! { |e| e.chomp }
end

def actual_lines
actual.split("\n").map! { |e| e.chomp }
@actual.split("\n").map! { |e| e.chomp }
end

def build_hunk(piece)
Expand All @@ -37,5 +37,4 @@ def context_lines
3
end

attr_reader :actual, :expected
end
14 changes: 6 additions & 8 deletions lib/rspec/expectations/encoded_string.rb
Expand Up @@ -17,22 +17,20 @@ def split(regex_or_string)
@string.split(matching_encoding(regex_or_string))
end

private

attr_reader :encoding
private

if String.method_defined?(:encoding)
def matching_encoding(string)
string.encode(encoding)
string.encode(@encoding)
rescue Encoding::UndefinedConversionError
normalize_missing(string.encode(encoding, :invalid => :replace, :undef => :replace))
normalize_missing(string.encode(@encoding, :invalid => :replace, :undef => :replace))
rescue Encoding::ConverterNotFoundError
normalize_missing(string.force_encoding(encoding).encode(:invalid => :replace))
normalize_missing(string.force_encoding(@encoding).encode(:invalid => :replace))
end

def normalize_missing(string)
if encoding.to_s == "UTF-8"
string.gsub("\xEF\xBF\xBD".force_encoding(encoding), "?")
if @encoding.to_s == "UTF-8"
string.gsub("\xEF\xBF\xBD".force_encoding(@encoding), "?")
else
string
end
Expand Down

0 comments on commit 29a618f

Please sign in to comment.