Skip to content

Commit

Permalink
Add method to filter a page's entries by time, resolves #9
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeasley committed Mar 26, 2019
1 parent 93a1132 commit fb7187b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/har/page.rb
Expand Up @@ -11,5 +11,13 @@ def initialize(input, entries)
# a little sugar
alias_method :timings, :page_timings

# Filter entries that *finished* before the specified time
def entries_before(time)
raise TypeError, "expected Time" unless time.is_a?(Time)
entries.select do |entry|
return false unless entry.time
entry.started_date_time + entry.time / 1000.0 < time
end
end
end
end
15 changes: 14 additions & 1 deletion spec/har/page_spec.rb
Expand Up @@ -18,7 +18,20 @@ module HAR
it "has a PageTimings instance" do
page.timings.should be_kind_of(PageTimings)
end
end

describe "#entries_before" do
it "requires a DateTime" do
expect { page.entries_before("a string") }.to raise_error(TypeError)
end

it "filters entries that responded before the specified time" do
time = page.started_date_time + 0.250
entries = page.entries_before(time)
entries.each do |entry|
(entry.started_date_time + entry.time / 1000.to_f).should < time
end
end
end
end
end # Page
end # HAR

0 comments on commit fb7187b

Please sign in to comment.