Skip to content

Instantly share code, notes, and snippets.

@kevinzen
Created April 16, 2012 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kevinzen/2400225 to your computer and use it in GitHub Desktop.
Save kevinzen/2400225 to your computer and use it in GitHub Desktop.
Advice on DRYing this test up?
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 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8' do
before do
@useragent = UserAgent.parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0b8) Gecko/20100101 Firefox/4.0b8')
end
it_should_behave_like "Firefox browser"
it "should return '4.0b8' as its version" do
@useragent.version.should == "4.0b8"
end
it "should return '20100101' as its gecko version" do
@useragent.gecko.version.should == "20100101"
end
it "should return 'Macintosh' as its platform" do
@useragent.platform.should == "Macintosh"
end
it "should return 'Intel Mac OS X 10.6' as its os" do
@useragent.os.should == "Intel Mac OS X 10.6"
end
it "should return nil as its localization" do
@useragent.localization.should be_nil
end
it { @useragent.should_not be_mobile }
end
describe 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13' do
before do
@useragent = UserAgent.parse('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13')
end
it_should_behave_like "Firefox browser"
it "should return '3.6.13' as its version" do
@useragent.version.should == "3.6.13"
end
it "should return '20101203' as its gecko version" do
@useragent.gecko.version.should == "20101203"
end
it "should return 'Macintosh' as its platform" do
@useragent.platform.should == "Macintosh"
end
it "should return 'Intel Mac OS X 10.6' as its os" do
@useragent.os.should == "Intel Mac OS X 10.6"
end
it "should return 'en-US' as its localization" do
@useragent.localization.should == "en-US"
end
it { @useragent.should_not be_mobile }
end
@kevinzen
Copy link
Author

I want to add like 40+ more test sections, but there's got to be a way to dry it up. Suggestions?

Original code here:

https://github.com/josh/useragent/blob/master/spec/browsers/gecko_user_agent_spec.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment