Skip to content

Instantly share code, notes, and snippets.

@mauricio
Created April 16, 2012 18:08
Show Gist options
  • Select an option

  • Save mauricio/2400425 to your computer and use it in GitHub Desktop.

Select an option

Save mauricio/2400425 to your computer and use it in GitHub Desktop.
shared_examples_for "firefox browser" do
it "should return 'Firefox' as its browser" do
@useragent.browser.should == "Firefox"
end
it "should return :strong as its security" do
@useragent.security.should == :strong
end
it { @useragent.should_not be_webkit }
end
describe 'When matching user agents' do
YAML.load( "user_agents.yml" ).each do |browser,agents|
context "When #{browser}" do
agents.each do |user_agent, properties|
context "When matching [#{user_agent}]" do
before do
@user_agent = UserAgent.parse( user_agent )
end
it should_behave_like "#{browser} browser"
it "should return #{properties['version']} as it's version" do
@user_agent.version.should == properties['version']
end
it "should return #{properties['platform']} as it's platform" do
@user_agent.platform.should == properties['platform']
end
it "should return '#{properties['os']}' as its os" do
@useragent.os.should == properties['os']
end
it "should return #{properties['localization'].inspect} as its localization" do
@useragent.localization.should == properties['localization']
end
end
end
end
end
end
Firefox:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8":
version: "4.0b8"
platform: Macintosh
os: "Intel Mac OS X 10.6"
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"
version: "3.6.13"
platform: Macintosh
os: "Intel Mac OS X 10.6"
localization: "en-US"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment