Skip to content
Browse files

Add quality spec that enforces whitespace policy.

  • Loading branch information...
1 parent a0f047e commit d34b6f7b67a48dde1d4dd6ea3be65a06c8fddfbb @myronmarston committed
Showing with 92 additions and 37 deletions.
  1. +1 −1 CHANGELOG.md
  2. +2 −2 benchmarks/http_stubbing_libraries.rb
  3. +1 −1 features/getting_started.md
  4. +55 −0 spec/quality_spec.rb
  5. +33 −33 spec/vcr/cassette/migrator_spec.rb
View
2 CHANGELOG.md
@@ -479,7 +479,7 @@ upgrade notes for more info.
* New Features
* Added support for [HTTPClient](http://github.com/nahi/httpclient), [Patron](http://github.com/toland/patron) and
[em-http-request](http://github.com/igrigorik/em-http-request) when WebMock is used. Any future http libraries
- WebMock supports should (theoretically, at least) work without any VCR code changes. Thanks to
+ WebMock supports should (theoretically, at least) work without any VCR code changes. Thanks to
[Bartosz Blimke](http://github.com/bblimke) for adding the necessary code to WebMock to make this happen!
* Added support for dynamic responses using ERB. A cassette will be evaluated as ERB before the YAML
is deserialized if you pass it an `:erb => true` option. You can pass variables using
View
4 benchmarks/http_stubbing_libraries.rb
@@ -52,8 +52,8 @@ def perform_benchmark(name)
# Benchmarking Single setup/teardown:
# webmock 0.000000 0.000000 6.950000 ( 6.981525)
# fakeweb 0.000000 0.010000 1.750000 ( 1.740679)
-#
-#
+#
+#
# Benchmarking Setup/teardown for each http request:
# webmock 0.000000 0.000000 7.970000 ( 7.981383)
# fakeweb 0.000000 0.000000 2.210000 ( 2.203478)
View
2 features/getting_started.md
@@ -55,7 +55,7 @@ Wrap the body of it (or at least the code that makes the HTTP request) in a
Run this test. It will record the HTTP request to disk as a cassette (a
test fixture), with content like:
- ---
+ ---
http_interactions:
- request:
method: get
View
55 spec/quality_spec.rb
@@ -0,0 +1,55 @@
+# Borrowed from:
+# https://github.com/carlhuda/bundler/blob/v1.1.rc.7/spec/quality_spec.rb
+require "spec_helper"
+
+if defined?(Encoding)
+ Encoding.default_external = "UTF-8"
+end
+
+describe "The library itself" do
+ def check_for_tab_characters(filename)
+ failing_lines = []
+ File.readlines(filename).each_with_index do |line,number|
+ failing_lines << number + 1 if line =~ /\t/
+ end
+
+ unless failing_lines.empty?
+ "#{filename} has tab characters on lines #{failing_lines.join(', ')}"
+ end
+ end
+
+ def check_for_extra_spaces(filename)
+ failing_lines = []
+ File.readlines(filename).each_with_index do |line,number|
+ next if line =~ /^\s+#.*\s+\n$/
+ failing_lines << number + 1 if line =~ /\s+\n$/
+ end
+
+ unless failing_lines.empty?
+ "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
+ end
+ end
+
+ RSpec::Matchers.define :be_well_formed do
+ failure_message_for_should do |actual|
+ actual.join("\n")
+ end
+
+ match do |actual|
+ actual.empty?
+ end
+ end
+
+ it "has no malformed whitespace" do
+ error_messages = []
+ Dir.chdir(File.expand_path("../..", __FILE__)) do
+ `git ls-files`.split("\n").each do |filename|
+ next if filename =~ /vendor|.feature|.yml|.gitmodules/
+ error_messages << check_for_tab_characters(filename)
+ error_messages << check_for_extra_spaces(filename)
+ end
+ end
+ error_messages.compact.should be_well_formed
+ end
+end
+
View
66 spec/vcr/cassette/migrator_spec.rb
@@ -3,38 +3,38 @@
describe VCR::Cassette::Migrator do
let(:original_contents) { <<-EOF
----
-- !ruby/struct:VCR::HTTPInteraction
- request: !ruby/struct:VCR::Request
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
method: :get
uri: http://example.com:80/foo
- body:
- headers:
- response: !ruby/struct:VCR::Response
- status: !ruby/struct:VCR::ResponseStatus
+ body:
+ headers:
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
- headers:
- content-type:
+ headers:
+ content-type:
- text/html;charset=utf-8
- content-length:
+ content-length:
- "9"
body: Hello foo
http_version: "1.1"
-- !ruby/struct:VCR::HTTPInteraction
- request: !ruby/struct:VCR::Request
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
method: :get
uri: http://localhost:7777/bar
- body:
- headers:
- response: !ruby/struct:VCR::Response
- status: !ruby/struct:VCR::ResponseStatus
+ body:
+ headers:
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
code: 200
message: OK
- headers:
- content-type:
+ headers:
+ content-type:
- text/html;charset=utf-8
- content-length:
+ content-length:
- "9"
body: Hello bar
http_version: "1.1"
@@ -42,9 +42,9 @@
}
let(:updated_contents) { <<-EOF
----
-http_interactions:
-- request:
+---
+http_interactions:
+- request:
method: get
uri: http://example.com/foo
body:
@@ -52,21 +52,21 @@
string: ""
headers: {}
- response:
- status:
+ response:
+ status:
code: 200
message: OK
- headers:
- Content-Type:
+ headers:
+ Content-Type:
- text/html;charset=utf-8
- Content-Length:
+ Content-Length:
- "9"
body:
encoding: UTF-8
string: Hello foo
http_version: "1.1"
recorded_at: Wed, 04 May 2011 12:30:00 GMT
-- request:
+- request:
method: get
uri: http://localhost:7777/bar
body:
@@ -74,14 +74,14 @@
string: ""
headers: {}
- response:
- status:
+ response:
+ status:
code: 200
message: OK
- headers:
- Content-Type:
+ headers:
+ Content-Type:
- text/html;charset=utf-8
- Content-Length:
+ Content-Length:
- "9"
body:
encoding: UTF-8

0 comments on commit d34b6f7

Please sign in to comment.
Something went wrong with that request. Please try again.