-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add helper methods for starting/stopping trace #66
Merged
Merged
Changes from all commits
Commits
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 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 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'tracing', sinatra: true do | ||
TRACES_DIR = 'tmp/capybara/playwright'.freeze | ||
|
||
before do | ||
FileUtils.rm_rf(TRACES_DIR) | ||
|
||
sinatra.get '/' do | ||
<<~HTML | ||
<!DOCTYPE html> | ||
<button>Go</button> | ||
HTML | ||
end | ||
end | ||
|
||
it 'can start and stop tracing' do | ||
page.driver.start_tracing(name: "test_trace", screenshots: true, snapshots: true, sources: true, title: "test_trace") | ||
|
||
visit '/' | ||
click_on 'Go' | ||
expect(page).to have_content('Go') | ||
|
||
page.driver.stop_tracing(path: "#{TRACES_DIR}/test_trace.zip") | ||
|
||
expect(File).to exist("#{TRACES_DIR}/test_trace.zip") | ||
end | ||
|
||
it 'can enable tracing only in the block' do | ||
page.driver.trace name: "test_trace_with_block", screenshots: true, snapshots: true, sources: true, title: "title", path: "#{TRACES_DIR}/test_trace_with_block.zip" do | ||
visit '/' | ||
click_on 'Go' | ||
expect(page).to have_content('Go') | ||
end | ||
|
||
expect(File).to exist("#{TRACES_DIR}/test_trace_with_block.zip") | ||
end | ||
|
||
it 'does not start tracing when no block is given' do | ||
expect { page.driver.trace }.to raise_error(ArgumentError) | ||
|
||
expect { | ||
page.driver.start_tracing | ||
page.driver.stop_tracing | ||
}.not_to raise_error(Playwright::Error, /Tracing has been already started/) | ||
end | ||
end |
Oops, something went wrong.
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.
@yuki24 I prefer the method name
with_tracing
for this. Do you have any ideas about this?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.
I think the name
with
implies that the wordtracing
is a thing, rather than being an action. For example, all the methods prefixed withwith_
in Rails follow the form ofwith_thing
, rather thanwith_doing
:Whereas other methods, such as
#draw
,#transaction
, and#freeze_time
, all trigger an explicit action under the hood, and the execution in the block is in effect of the action you would like to take. I believe this case is closer to the latter.So based on this assessment, I would think that the name
#trace
is more intuitive than#with_tracing
.With that all said, this is ultimately your call. Let me know what you think.
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.
Thank you for your kind advices.
I didn't know well about the Rails existing method names and its rules, and your advices really helped me.
Let's keep the method name 'with_trace' here.