Skip to content

Commit cefaf2d

Browse files
author
Alex Egan
committed
add whitespace checks and fix end of line whitespace
This adds the file spec/rspec/rails_spec.rb to check for whitespace problems using the RSpec::Support::WhitespaceChecks module from PR rspec#232 in rspec-support. This also removes trailing whitespace from three files in the features directory
1 parent 4fbb4aa commit cefaf2d

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

features/Transactions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ already ran. For example:
3838
it "does something" do
3939
expect(@widget).to do_something
4040
end
41-
41+
4242
it "does something else" do
4343
expect(@widget).to do_something_else
4444
end
@@ -47,7 +47,7 @@ already ran. For example:
4747
The `@widget` is recreated in each of the two examples above, so each example
4848
has a different object, _and_ the underlying data is rolled back so the data
4949
backing the `@widget` in each example is new.
50-
50+
5151
### Data created in `before(:all)` are _not_ rolled back
5252

5353
`before(:all)` hooks are invoked before the transaction is opened. You can use

features/controller_specs/Cookies.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ the following guidelines:
1313
* Access cookies through the `request` and `response` objects in the spec.
1414
* Use `request.cookies` before the action to set up state.
1515
* Use `response.cookies` after the action to specify outcomes.
16-
* Use the `cookies` object in the controller action.
16+
* Use the `cookies` object in the controller action.
1717
* Use String keys.
1818

1919
<pre>
@@ -42,7 +42,7 @@ sticking with string keys for consistency.
4242

4343
The `cookies` method combines the `request` and `response` cookies. This can
4444
lead to confusion when setting cookies in the example in order to set up state
45-
for the controller action.
45+
for the controller action.
4646

4747
# does not work in rails 3.0.0 > 3.1.0
4848
cookies['foo'] = 'bar' # this is not visible in the controller
@@ -51,7 +51,6 @@ for the controller action.
5151
### Future versions of Rails
5252

5353
There is code in the master branch in rails that makes cookie access more
54-
consistent so you can use the same `cookies` object before and after the action,
54+
consistent so you can use the same `cookies` object before and after the action,
5555
and you can use String or Symbol keys. We'll update these docs accordingly when
5656
that is released.
57-

features/matchers/new_record_matcher.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: be_a_new matcher
66
You can also chain `with` on `be_a_new` with a hash of attributes to specify
77
the subject has equal attributes.
88

9-
Scenario: example spec with four be_a_new possibilities
9+
Scenario: example spec with four be_a_new possibilities
1010
Given a file named "spec/models/widget_spec.rb" with:
1111
"""ruby
1212
require "rails_helper"

spec/rspec/rails_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'rspec/support/spec/library_wide_checks'
2+
3+
RSpec.describe "RSpec::Rails" do
4+
include RSpec::Support::WhitespaceChecks
5+
6+
# Pasted from rspec-support lib/rspec/support/spec/library_wide_checks.rb:134
7+
# Easier to do that here than to extract it out
8+
RSpec::Matchers.define :be_well_formed do
9+
match do |actual|
10+
actual.empty?
11+
end
12+
13+
failure_message do |actual|
14+
actual.join("\n")
15+
end
16+
end
17+
18+
it "has no malformed whitespace", :slow do
19+
error_messages = []
20+
`git ls-files -z`.split("\x0").each do |filename|
21+
error_messages << check_for_tab_characters(filename)
22+
error_messages << check_for_extra_spaces(filename)
23+
end
24+
expect(error_messages.compact).to be_well_formed
25+
end
26+
end

0 commit comments

Comments
 (0)