require File.dirname(__FILE__) + '/test_helper.rb' require 'test/unit' require 'rubygems' require 'mocha' class WoopraAnalyticsTest < Test::Unit::TestCase def setup @wa = JonathanNelson::WoopraAnalytics.new end def test_createable assert_not_nil(@wa) end def test_domain_name_defaults_to_nil assert_nil(@wa.domain_name) end def test_default_environments assert_equal(false, @wa.environments.include?('test')) assert_equal(false, @wa.environments.include?('development')) assert_equal(true, @wa.environments.include?('production')) end def test_default_formats assert_equal(false, @wa.formats.include?(:xml)) assert_equal(true, @wa.formats.include?(:html)) end def test_defer_load_defaults_to_true assert_equal(true, @wa.defer_load) end def test_local_javascript_defaults_to_false assert_equal(false, @wa.local_javascript) end # test self.enabled def test_enabled_requires_analytics_url JonathanNelson::WoopraAnalytics.stubs(:analytics_url).returns(nil) assert_raise(JonathanNelson::WoopraAnalyticsConfigurationError) { JonathanNelson::WoopraAnalytics.enabled?(:html) } end def test_enabled_returns_false_if_current_environment_not_enabled assert_equal(false, JonathanNelson::WoopraAnalytics.enabled?(:html)) end def test_enabled_with_default_format JonathanNelson::WoopraAnalytics.stubs(:environments).returns(['test']) assert_equal(true, JonathanNelson::WoopraAnalytics.enabled?(:html)) end def test_enabled_with_not_included_format JonathanNelson::WoopraAnalytics.stubs(:environments).returns(['test']) assert_equal(false, JonathanNelson::WoopraAnalytics.enabled?(:xml)) end def test_enabled_with_added_format JonathanNelson::WoopraAnalytics.stubs(:environments).returns(['test']) JonathanNelson::WoopraAnalytics.stubs(:formats).returns([:xml]) assert_equal(true, JonathanNelson::WoopraAnalytics.enabled?(:xml)) end end