Skip to content

Commit

Permalink
merged similar specs into one
Browse files Browse the repository at this point in the history
  • Loading branch information
SidOfc committed Apr 23, 2017
1 parent bd0e72f commit 8c63d60
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 138 deletions.
4 changes: 4 additions & 0 deletions lib/browserino/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def like(tmp, &block)
preset like: tmp.to_sym, &block
end

def validators(&block)
preset type: :validator, &block
end

def browsers(&block)
preset type: :browser, &block
end
Expand Down
17 changes: 17 additions & 0 deletions lib/browserino/definitions/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,23 @@
match %r{curl}i, name: :curl
end

# automatically set type to :library for each defined matcher
validators do
match %r{cse\shtml\svalidator}i, name: :cse_html_validator
match %r{csschecl}i, name: :csschecl
match %r{htmlparser}i, name: :htmlparser
match %r{p3p_validator}i, name: :p3p_validator
match %r{wdg_validator}i, name: :wdg_validator
match %r{w3c_validator}i, name: :w3c_validator

match %r{cynthia}i, name: :cynthia,
version: %r{cynthia\s([\d\.]+)}i

match %r{w3c_css_validator}i,
name: :w3c_validator,
version: %r{w3c_css_validator_jfouffa/([\d\.]+)}i
end

# inherit properties a standard set of properties by the name of a
# previously defined matcher, overwritten by properties added within matchers
# inherit properties from Identity where name == :chrome
Expand Down
67 changes: 0 additions & 67 deletions spec/bot_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
browsers = Library.data.fetch(:browsers, [])

browsers.each do |spec|
exclude = [:user_agent, :mobile, :to_s]
client = Browserino.parse spec[:user_agent]
exclude = [:user_agent, :mobile, :to_s]
client = Browserino.parse spec[:user_agent]

describe [client.name, spec[:user_agent]].join(' :: ') do
if client.type != :unknown
Expand Down
69 changes: 0 additions & 69 deletions spec/library_spec.rb

This file was deleted.

70 changes: 70 additions & 0 deletions spec/non_browser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'spec_helper'

TYPE_MAP = { validators: :validator, bots: :bot, libraries: :library }
(Library.data.keys - [:browsers]).each do |type|
describe "Browserino #{type}" do
Library.data.fetch(type, []).each do |spec|
ua = spec.delete :user_agent
client = Browserino.parse ua
spec[:type] ||= TYPE_MAP[type]

describe [client.name, ua].join(' :: ') do
if spec[:to_s]
it "expects client.to_s to be #{spec[:to_s]}" do
expect(client.to_s).to eq spec[:to_s]
end
end

spec.reject { |k, _| k == :to_s }.each do |test_method, test_result|
it "expects #{test_method} to be #{test_result}" do
expect(client.send(test_method)).to eq test_result
end

it "expects client.#{test_method}? #{test_result && ":#{test_result}"} to be #{test_result && 'truthy' || 'falsy'}" do
if test_result
expect(client.send("#{test_method}?", test_result)).to be_truthy
else
expect(client.send("#{test_method}?", test_result)).to be_falsy
end
end
end

# test magic aliasses when defined
Browserino.config.aliasses[spec[:name]].each do |alt|
it "expects client.#{alt}? to be truthy" do
expect(client.send("#{alt}?")).to be_truthy
end

if spec[:version]
it "expects client.#{alt}? #{spec[:version]} to be truthy}" do
expect(client.send("#{alt}?", spec[:version])).to be_truthy
end
end
end

# test magic name methods when possible
unless spec[:name].to_s.strip.empty?
name = "#{spec[:name]}?"
it "expects client.#{name} to be truthy" do
expect(client.send("#{name}")).to be_truthy
end

it "expects client.is? :#{spec[:name]} to be truthy" do
expect(client.is?(spec[:name])).to be_truthy
end

unless spec[:version].to_s.strip.empty?
name_ver = spec[:version]
it "expects client.#{name} '#{name_ver}' to be truthy" do
expect(client.send("#{name}", name_ver.to_s)).to be_truthy
end

it "expects client.is? :#{spec[:name]}, version: #{name_ver} to be truthy" do
expect(client.is?(spec[:name], version: name_ver)).to be_truthy
end
end
end
end
end
end
end

0 comments on commit 8c63d60

Please sign in to comment.