Skip to content
Browse files

Share parser for parse specs. Speeds up tests enough to be worth the …

…dirtiness I feel inside for doing it.

The main slowness of the test suite was constantly reading the regexes
from disk and parsing them for each new spec.

This makes it so the parser loads the patterns once and parses them
with yaml once for all the #parse specs.

On my machine, the test suite went from like 2 minutes to 7 seconds.
*DRAMATIC HAMSTER*
  • Loading branch information...
1 parent a2824a2 commit a65226172b20c40d8ea8bb86fc5950c3d7c052de @jnunemaker committed Jan 7, 2013
Showing with 6 additions and 2 deletions.
  1. +2 −2 spec/parser_spec.rb
  2. +4 −0 spec/spec_helper.rb
View
4 spec/parser_spec.rb
@@ -60,7 +60,7 @@ def self.operating_system_test_cases
describe "#parse" do
user_agent_test_cases.each do |test_case|
it "parses UA for #{test_case_to_test_name(test_case)}" do
- user_agent = UserAgentParser::Parser.new.parse(test_case['user_agent_string'])
+ user_agent = PARSER.parse(test_case['user_agent_string'])
if test_case['family']
user_agent.family.must_equal_test_case_property(test_case, 'family')
@@ -82,7 +82,7 @@ def self.operating_system_test_cases
operating_system_test_cases.each do |test_case|
it "parses OS for #{test_case_to_test_name(test_case)}" do
- user_agent = UserAgentParser::Parser.new.parse(test_case['user_agent_string'])
+ user_agent = PARSER.parse(test_case['user_agent_string'])
if test_case['family']
user_agent.os.name.must_equal_test_case_property(test_case, 'family')
View
4 spec/spec_helper.rb
@@ -23,3 +23,7 @@ def assert_test_case_property_equal(test_case, actual, test_case_property)
Object.infect_an_assertion :assert_test_case_property_equal, :must_equal_test_case_property
end
end
+
+# Get instance of parser and preload patterns by calling #parse.
+PARSER = UserAgentParser::Parser.new
+PARSER.parse('')

0 comments on commit a652261

Please sign in to comment.
Something went wrong with that request. Please try again.