Skip to content

Commit 2fc446f

Browse files
thincarwz
authored andcommitted
Avoid warning on test (#360)
> warning: ambiguous first argument; put parentheses or a space even after `/' operator
1 parent a66d0f3 commit 2fc446f

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

test/jbuilder_generator_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ class JbuilderGeneratorTest < Rails::Generators::TestCase
2121
run_generator
2222

2323
assert_file 'app/views/posts/index.json.jbuilder' do |content|
24-
assert_match /json.array! @posts, partial: 'posts\/post', as: :post/, content
24+
assert_match %r{json.array! @posts, partial: 'posts/post', as: :post}, content
2525
end
2626

2727
assert_file 'app/views/posts/show.json.jbuilder' do |content|
28-
assert_match /json.partial! \"posts\/post\", post: @post/, content
28+
assert_match %r{json.partial! \"posts/post\", post: @post}, content
2929
end
3030

3131
assert_file 'app/views/posts/_post.json.jbuilder' do |content|
32-
assert_match /json\.extract! post, :id, :title, :body/, content
33-
assert_match /json\.url post_url\(post, format: :json\)/, content
32+
assert_match %r{json\.extract! post, :id, :title, :body}, content
33+
assert_match %r{json\.url post_url\(post, format: :json\)}, content
3434
end
3535

3636

test/scaffold_api_controller_generator_test.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,40 @@ class ScaffoldApiControllerGeneratorTest < Rails::Generators::TestCase
1515

1616
assert_file 'app/controllers/posts_controller.rb' do |content|
1717
assert_instance_method :index, content do |m|
18-
assert_match /@posts = Post\.all/, m
18+
assert_match %r{@posts = Post\.all}, m
1919
end
2020

2121
assert_instance_method :show, content do |m|
2222
assert m.blank?
2323
end
2424

2525
assert_instance_method :create, content do |m|
26-
assert_match /@post = Post\.new\(post_params\)/, m
27-
assert_match /@post\.save/, m
28-
assert_match /render :show, status: :created, location: @post/, m
29-
assert_match /render json: @post\.errors, status: :unprocessable_entity/, m
26+
assert_match %r{@post = Post\.new\(post_params\)}, m
27+
assert_match %r{@post\.save}, m
28+
assert_match %r{render :show, status: :created, location: @post}, m
29+
assert_match %r{render json: @post\.errors, status: :unprocessable_entity}, m
3030
end
3131

3232
assert_instance_method :update, content do |m|
33-
assert_match /render :show, status: :ok, location: @post/, m
34-
assert_match /render json: @post.errors, status: :unprocessable_entity/, m
33+
assert_match %r{render :show, status: :ok, location: @post}, m
34+
assert_match %r{render json: @post.errors, status: :unprocessable_entity}, m
3535
end
3636

3737
assert_instance_method :destroy, content do |m|
38-
assert_match /@post\.destroy/, m
38+
assert_match %r{@post\.destroy}, m
3939
end
4040

41-
assert_match /def post_params/, content
42-
assert_match /params\.require\(:post\)\.permit\(:title, :body\)/, content
41+
assert_match %r{def post_params}, content
42+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body\)}, content
4343
end
4444
end
4545

4646
test 'dont use require and permit if there are no attributes' do
4747
run_generator %w(Post --api)
4848

4949
assert_file 'app/controllers/posts_controller.rb' do |content|
50-
assert_match /def post_params/, content
51-
assert_match /params\.fetch\(:post, {}\)/, content
50+
assert_match %r{def post_params}, content
51+
assert_match %r{params\.fetch\(:post, \{\}\)}, content
5252
end
5353
end
5454
end

test/scaffold_controller_generator_test.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,54 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
1313

1414
assert_file 'app/controllers/posts_controller.rb' do |content|
1515
assert_instance_method :index, content do |m|
16-
assert_match /@posts = Post\.all/, m
16+
assert_match %r{@posts = Post\.all}, m
1717
end
1818

1919
assert_instance_method :show, content do |m|
2020
assert m.blank?
2121
end
2222

2323
assert_instance_method :new, content do |m|
24-
assert_match /@post = Post\.new/, m
24+
assert_match %r{@post = Post\.new}, m
2525
end
2626

2727
assert_instance_method :edit, content do |m|
2828
assert m.blank?
2929
end
3030

3131
assert_instance_method :create, content do |m|
32-
assert_match /@post = Post\.new\(post_params\)/, m
33-
assert_match /@post\.save/, m
34-
assert_match /format\.html \{ redirect_to @post, notice: 'Post was successfully created\.' \}/, m
35-
assert_match /format\.json \{ render :show, status: :created, location: @post \}/, m
36-
assert_match /format\.html \{ render :new \}/, m
37-
assert_match /format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}/, m
32+
assert_match %r{@post = Post\.new\(post_params\)}, m
33+
assert_match %r{@post\.save}, m
34+
assert_match %r{format\.html \{ redirect_to @post, notice: 'Post was successfully created\.' \}}, m
35+
assert_match %r{format\.json \{ render :show, status: :created, location: @post \}}, m
36+
assert_match %r{format\.html \{ render :new \}}, m
37+
assert_match %r{format\.json \{ render json: @post\.errors, status: :unprocessable_entity \}}, m
3838
end
3939

4040
assert_instance_method :update, content do |m|
41-
assert_match /format\.html \{ redirect_to @post, notice: 'Post was successfully updated\.' \}/, m
42-
assert_match /format\.json \{ render :show, status: :ok, location: @post \}/, m
43-
assert_match /format\.html \{ render :edit \}/, m
44-
assert_match /format\.json \{ render json: @post.errors, status: :unprocessable_entity \}/, m
41+
assert_match %r{format\.html \{ redirect_to @post, notice: 'Post was successfully updated\.' \}}, m
42+
assert_match %r{format\.json \{ render :show, status: :ok, location: @post \}}, m
43+
assert_match %r{format\.html \{ render :edit \}}, m
44+
assert_match %r{format\.json \{ render json: @post.errors, status: :unprocessable_entity \}}, m
4545
end
4646

4747
assert_instance_method :destroy, content do |m|
48-
assert_match /@post\.destroy/, m
49-
assert_match /format\.html \{ redirect_to posts_url, notice: 'Post was successfully destroyed\.' \}/, m
50-
assert_match /format\.json \{ head :no_content \}/, m
48+
assert_match %r{@post\.destroy}, m
49+
assert_match %r{format\.html \{ redirect_to posts_url, notice: 'Post was successfully destroyed\.' \}}, m
50+
assert_match %r{format\.json \{ head :no_content \}}, m
5151
end
5252

53-
assert_match /def post_params/, content
54-
assert_match /params\.require\(:post\)\.permit\(:title, :body\)/, content
53+
assert_match %r{def post_params}, content
54+
assert_match %r{params\.require\(:post\)\.permit\(:title, :body\)}, content
5555
end
5656
end
5757

5858
test 'dont use require and permit if there are no attributes' do
5959
run_generator %w(Post)
6060

6161
assert_file 'app/controllers/posts_controller.rb' do |content|
62-
assert_match /def post_params/, content
63-
assert_match /params\.fetch\(:post, {}\)/, content
62+
assert_match %r{def post_params}, content
63+
assert_match %r{params\.fetch\(:post, \{\}\)}, content
6464
end
6565
end
6666
end

0 commit comments

Comments
 (0)