-
Notifications
You must be signed in to change notification settings - Fork 657
Refactor test cases of AnnotateRoutes as for Rake versions #754
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
Merged
drwl
merged 6 commits into
ctran:develop
from
nard-tech:feature/refactor_annotate_routes/rspec_v3
Feb 13, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
40250d4
Unify describe clauses as for Rake versions
nard-tech 0d6e6fa
Refactor test cases of AnnotateRoutes.do_annotations with Rake versions
nard-tech 1302d80
Define variables using let
nard-tech 949cf0c
Refactor test cases using before section
nard-tech 4060875
Execute `rubocop --auto-gen-config`
nard-tech 25f7b4a
Merge branch 'develop' into feature/refactor_annotate_routes/rspec_v3
nard-tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,51 +271,163 @@ | |
end | ||
end | ||
|
||
describe 'When adding with older Rake versions' do | ||
before(:each) do | ||
describe 'As for Rake versions' do | ||
before :each do | ||
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true) | ||
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("(in /bad/line)\ngood line") | ||
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) | ||
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED) | ||
end | ||
expect(File).to receive(:read).with(ROUTE_FILE).and_return(route_file_content) | ||
|
||
it 'should annotate and add a newline!' do | ||
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo") | ||
expect(mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/) | ||
AnnotateRoutes.do_annotations | ||
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return(rake_routes_result) | ||
end | ||
|
||
it 'should not add a newline if there are empty lines' do | ||
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo\n") | ||
expect(mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# good line\n/) | ||
AnnotateRoutes.do_annotations | ||
end | ||
end | ||
context 'with older Rake versions' do | ||
let :rake_routes_result do | ||
<<~EOS.chomp | ||
(in /bad/line) | ||
good line | ||
EOS | ||
end | ||
|
||
describe 'When adding with newer Rake versions' do | ||
before(:each) do | ||
expect(File).to receive(:exist?).with(ROUTE_FILE).and_return(true) | ||
expect(AnnotateRoutes).to receive(:`).with('rake routes').and_return("another good line\ngood line") | ||
expect(File).to receive(:open).with(ROUTE_FILE, 'wb').and_yield(mock_file) | ||
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED) | ||
end | ||
context 'When the route file does not end with an empty line' do | ||
let :route_file_content do | ||
<<~EOS.chomp | ||
ActionController::Routing... | ||
foo | ||
EOS | ||
end | ||
|
||
it 'should annotate and add a newline!' do | ||
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo") | ||
expect(mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/) | ||
AnnotateRoutes.do_annotations | ||
end | ||
let :expected_result do | ||
<<~EOS | ||
ActionController::Routing... | ||
foo | ||
|
||
it 'should not add a newline if there are empty lines' do | ||
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo\n") | ||
expect(mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map\n#\n# another good line\n# good line\n/) | ||
AnnotateRoutes.do_annotations | ||
# == Route Map | ||
# | ||
# good line | ||
EOS | ||
end | ||
|
||
it 'annotates with an empty line' do | ||
expect(mock_file).to receive(:puts).with(expected_result) | ||
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED) | ||
|
||
AnnotateRoutes.do_annotations | ||
end | ||
end | ||
|
||
context 'When the route file ends with an empty line' do | ||
let :route_file_content do | ||
<<~EOS | ||
ActionController::Routing... | ||
foo | ||
EOS | ||
end | ||
|
||
let :expected_result do | ||
<<~EOS | ||
ActionController::Routing... | ||
foo | ||
|
||
# == Route Map | ||
# | ||
# good line | ||
EOS | ||
end | ||
|
||
it 'annotates without an empty line' do | ||
expect(mock_file).to receive(:puts).with(expected_result) | ||
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with |
||
|
||
AnnotateRoutes.do_annotations | ||
end | ||
end | ||
end | ||
|
||
it 'should add a timestamp when :timestamp is passed' do | ||
expect(File).to receive(:read).with(ROUTE_FILE).and_return("ActionController::Routing...\nfoo") | ||
expect(mock_file).to receive(:puts).with(/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/) | ||
AnnotateRoutes.do_annotations timestamp: true | ||
context 'with newer Rake versions' do | ||
let :rake_routes_result do | ||
<<~EOS.chomp | ||
another good line | ||
good line | ||
EOS | ||
end | ||
|
||
context 'When the route file does not end with an empty line' do | ||
context 'When no option is passed' do | ||
let :route_file_content do | ||
<<~EOS.chomp | ||
ActionController::Routing... | ||
foo | ||
EOS | ||
end | ||
|
||
let :expected_result do | ||
<<~EOS | ||
ActionController::Routing... | ||
foo | ||
|
||
# == Route Map | ||
# | ||
# another good line | ||
# good line | ||
EOS | ||
end | ||
|
||
it 'annotates with an empty line' do | ||
expect(mock_file).to receive(:puts).with(expected_result) | ||
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED) | ||
|
||
AnnotateRoutes.do_annotations | ||
end | ||
end | ||
end | ||
|
||
context 'When the route file ends with an empty line' do | ||
let :route_file_content do | ||
<<~EOS | ||
ActionController::Routing... | ||
foo | ||
EOS | ||
end | ||
|
||
let :expected_result do | ||
<<~EOS | ||
ActionController::Routing... | ||
foo | ||
|
||
# == Route Map | ||
# | ||
# another good line | ||
# good line | ||
EOS | ||
end | ||
|
||
it 'annotates without an empty line' do | ||
expect(mock_file).to receive(:puts).with(expected_result) | ||
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED) | ||
|
||
AnnotateRoutes.do_annotations | ||
end | ||
end | ||
|
||
context 'When option "timestamp" is passed' do | ||
let :route_file_content do | ||
<<~EOS.chomp | ||
ActionController::Routing... | ||
foo | ||
EOS | ||
end | ||
|
||
let :expected_result do | ||
/ActionController::Routing...\nfoo\n\n# == Route Map \(Updated \d{4}-\d{2}-\d{2} \d{2}:\d{2}\)\n#\n# another good line\n# good line\n/ | ||
end | ||
|
||
it 'annotates with the timestamp and an empty line' do | ||
expect(mock_file).to receive(:puts).with(expected_result) | ||
expect(AnnotateRoutes).to receive(:puts).with(MESSAGE_ANNOTATED) | ||
|
||
AnnotateRoutes.do_annotations timestamp: true | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting 🤔. I had no idea that when you do
It sends the message with method name `. Very neat.