Skip to content

Commit

Permalink
Merge pull request yeoman#509 from gnuwilliam/insight-tests
Browse files Browse the repository at this point in the history
Insight tests
  • Loading branch information
ebidel committed Sep 23, 2012
2 parents d89ebec + b595a2f commit 2558702
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/bin/yeomaninsight.py
Expand Up @@ -31,6 +31,9 @@ class Analytics(object):
BASE_URL = 'http://www.google-analytics.com/collect/__utm.gif'

def __init__(self, tracking_code):
if not tracking_code:
raise Exception('No tracking code is given')

self.tracking_code = tracking_code
self.do_stats = True

Expand Down
25 changes: 25 additions & 0 deletions cli/test/test-insight.py
@@ -0,0 +1,25 @@
#!/usr/bin/env python

import sys
import unittest
import os

sys.path.append('../bin/')

from yeomaninsight import main, Analytics

class YeomanInsightTest(unittest.TestCase):

def test_init_should_error_when_no_tracking_code_is_passed(self):
self.assertRaises(Exception, Analytics, tracking_code='')

def test_main_should_error_when_arguments_are_less_than_two(self):
# temporally disables print function, because it's used on main.
# just to keep the tests output clean.
sys.stdout = open(os.devnull, 'w')
self.assertRaises(SystemExit, main, args='')
# restores print function.
sys.stdout = sys.__stdout__

if __name__ == '__main__':
unittest.main()

0 comments on commit 2558702

Please sign in to comment.