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

Fixes misleading error message #705

Open
wants to merge 5 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/webmock/request_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def to_s
else
text = ""
self.requested_signatures.each do |request_signature, times_executed|
text << "#{request_signature} was made #{times_executed} time#{times_executed == 1 ? '' : 's' }\n"
text.force_encoding('ASCII-8BIT') << "#{request_signature} was made #{times_executed} time#{times_executed == 1 ? '' : 's' }\n"
end
text
end
Expand Down
7 changes: 4 additions & 3 deletions spec/quality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def check_for_tab_characters(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line,number|
failing_lines << number + 1 if line =~ /\t/
failing_lines << number + 1 if line.force_encoding('UTF-8') =~ /\t/
end

unless failing_lines.empty?
Expand All @@ -41,7 +41,8 @@ def check_for_tab_characters(filename)
def check_for_extra_spaces(filename)
failing_lines = []
File.readlines(filename).each_with_index do |line,number|
next if line =~ /^\s+#.*\s+\n$/
line.force_encoding('UTF-8') =~ /^\s+#.*\s+\n$/
next if line.force_encoding('UTF-8') =~ /^\s+#.*\s+\n$/
failing_lines << number + 1 if line =~ /\s+\n$/
end

Expand All @@ -64,7 +65,7 @@ def check_for_extra_spaces(filename)
error_messages = []
Dir.chdir(File.expand_path("../..", __FILE__)) do
`git ls-files`.split("\n").each do |filename|
next if filename =~ /\.gitmodules|fixtures/
next if filename =~ /\.gitmodules|fixtures|support/
error_messages << check_for_tab_characters(filename)
error_messages << check_for_extra_spaces(filename)
end
Expand Down
16 changes: 16 additions & 0 deletions test/shared_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def setup
super
@stub_http = stub_http_request(:any, "http://www.example.com")
@stub_https = stub_http_request(:any, "https://www.example.com")
@body1 = File.read(File.expand_path('test/support/body1'))
@body2 = File.read(File.expand_path('test/support/body2')).force_encoding('ASCII-8BIT')
end

def test_assert_requested_with_stub_and_block_raises_error
Expand Down Expand Up @@ -62,6 +64,20 @@ def test_verification_that_expected_request_occured_with_body_and_headers
body: "abc", headers: {'A' => 'a'})
end

def test_verification_that_expected_request_occured_with_utf8_body_and_headers
http_request(:post, "http://www.example.com/",
body: @body1, headers: {'A' => 'a'})
http_request(:post, "http://www.example.com/",
body: @body2, headers: {'A' => 'a'})
assert_fail(/.*/) do
# we know this will fail, but it shouldn't cause an exception
assert_requested(:post, "http://www.example.com",
body: @body1, headers: {'A' => 'b'})
end
rescue Encoding::CompatibilityError => e
flunk e.message
end

def test_verification_that_expected_request_occured_with_query_params
stub_request(:any, "http://www.example.com").with(query: hash_including({"a" => ["b", "c"]}))
http_request(:get, "http://www.example.com/?a[]=b&a[]=c&x=1")
Expand Down
Binary file added test/support/body1
Binary file not shown.
Binary file added test/support/body2
Binary file not shown.