kevinelliott / agent_orange

Parse and process User Agents like a secret one
126 stars 36 forks source link

Create tests #2

Closed kevinelliott closed 12 years ago

kevinelliott commented 13 years ago

The project currently has no tests. Before Milestone 0.1.0 is hit, we should have tests will full coverage.

joshuasiler commented 13 years ago

Hi. I added a test rake task in my pull request, that includes the user-agents.org list. Need more assertions to be considered "full coverage".

davidjrice commented 13 years ago

Would be very useful to have some very explicit tests as well as what @eatenbyagrue has done as a full "integration" style test. That way, can easily iterate on the lib and not worry about testing all the user agents.

@eatenbyagrue perhaps a CSV would be better to be able to add / edit the test data ?

davidjrice commented 13 years ago

So, I had a go at writing some specs (with rspec). I've sent a pull request from my "tests" branch.

I spent some time yak shaving to try and create a better DSL for the specs. I got something like the following working, only there was a bug which meant it wasn't working at all when I added more than one test. doh. I'll try some other things when I get time again... as it would be quite nice.

The one in my repo is a lot more ugly. However it raises the point, should we change agent_orange to provide accessors for all the main objects off of the user_agent object itself ? As that's what most of my hacks were doing.

describe "Firefox" do
  detect "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0" do |ua|
    ua.device :type => :computer, :name => "Computer"
    ua.os :name => "Linux", :version => "i686"
    ua.platform :name => "PC"
    ua.engine :name => "Gecko", :version => "20100101"
    ua.browser :name => "Firefox", :version => "6.0"
  end
end

And the output.

rspec spec/ --format documentation
AgentOrange::UserAgent
  Chrome
    Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.872.0 Safari/535.2
      device.type should == computer
      device.name should == Computer
      operating_system.name should == Windows
      operating_system.version should == 5.1
      platform.name should == PC
      engine.name should == AppleWebKit
      engine.version should == 535.2
      browser.name should == Chrome (PENDING: seems to be matching as Safari)
      browser.version should == 535.2 (PENDING: seems to be matching as Safari)
kevinelliott commented 13 years ago

David, thanks for starting to create rspec tests. It will be a valuable contribution to the project!

We will have to refactor how the detection algorithm for browser works in order to correct your output above. I think we'll want to prioritize matching browsers by order (so for above, Chrome shows up before Safari, thus it should be Chrome). Once I get the outstanding pull requests merged in, we'll look at it.

kevinelliott commented 13 years ago

davidjrice added some initial rpsec tests. I've merged in those additions. This is a great start. I'd like to see this evolve over time, and his choice of using rspec was good because it keeps things standard, and most people seem to be familiar with it. I'd like to keep this issue open for a while, as we test the tests, as well as integrate the project on travis CI.

kevinelliott commented 13 years ago

We need to figure out how to have the bundler rake actions in addition to having a default rake task that executes the rspecs. Any ideas?

kevinelliott commented 12 years ago

Testing is failing on "checking with real browsers list". New issue created.

kevinelliott commented 12 years ago

Tests are in place, and now working again correctly. I will create a new issue to implement more exhaustive testing against deeper code.