target_practice 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,3 +1,69 @@
1
1
  ## Target Practice
2
2
 
3
3
  A Ruby library for running Target Practice (.tp) test bundles.
4
+
5
+ ## Installation
6
+
7
+ Put the following in your Gemfile
8
+
9
+ gem 'target_practice'
10
+
11
+ Cool.
12
+
13
+ ## Writing TargetPractice tests.
14
+
15
+ TargetPractice tests work by comparing a JSON file to an object that you specify.
16
+ This allows you to write simple that are language agnostic. Nifty.
17
+
18
+ Let's take a look at a hypothetical example, parsing a PSD.
19
+
20
+ In my Rakefile:
21
+
22
+ require 'rubygems'
23
+ require 'rake/testtask'
24
+ require 'test/psdtest'
25
+
26
+ TargetPractice.new(:test) do |test|
27
+ test.pattern = "test/psd.tp/**/*.json"
28
+ test.test_class = PSDTest
29
+ end
30
+
31
+ And a simple test case `test/psd.tp/simple.json`:
32
+
33
+ {
34
+ "_title": "CMYK Header",
35
+ "_file": "fixtures/test-cmyk8.psd",
36
+ "psd": {
37
+ "height": 1
38
+ }
39
+ }
40
+
41
+ And my PSD test harness:
42
+
43
+ TP_ROOT = 'test/psd.tp/'
44
+
45
+ class PSDTest < TargetPracticeTestCase
46
+ def tests_against_files
47
+ @@files.each do |file|
48
+ @@current_file = file
49
+ do_file_test(file)
50
+ end
51
+ end
52
+
53
+ def do_file_test(file)
54
+ puts "Starting test for #{file}"
55
+ test_data = JSON.parse(File.open(file, 'r').read)
56
+ assert test_data["_file"], "Input file was not provided!"
57
+ psd = PSD.from_file(TP_ROOT + test_data["_file"])
58
+ psd.parse
59
+
60
+ assert_attributes(psd, test_data["psd"])
61
+ end
62
+ end
63
+
64
+ A little wordy, but this will ensure that if a PSD-parsing module existed, when parsing the
65
+ file defined in the JSON, it should have the height attribute equal to 1. If not, it fails.
66
+
67
+ ## Authors
68
+
69
+ TargetPractice was developed by [Kelly Sutton](http://github.com/kellysutton) for [LayerVault](http://layervault.com).
@@ -10,4 +10,34 @@ class TargetPracticeTestCase < MiniTest::Unit::TestCase
10
10
  def files=(f)
11
11
  @@files = f
12
12
  end
13
+
14
+ def assert_attributes(obj, hash={})
15
+ return if hash.nil?
16
+
17
+ hash.each do |k,v|
18
+ assert obj.send(k.to_sym) if !is_meta_command?(k)
19
+
20
+ if is_meta_command? k
21
+ perform_meta_assertion(obj, k, v)
22
+ elsif v.kind_of? Array
23
+ index = 0
24
+ v.each do |i|
25
+ assert_attributes(obj.send(k.to_sym)[index], i)
26
+ index += 1
27
+ end
28
+ elsif v.kind_of? Hash
29
+ assert_attributes(obj.send(k.to_sym), v)
30
+ elsif v.kind_of? String
31
+ assert_equal v, obj.send(k.to_sym)
32
+ end
33
+ end
34
+ end
35
+
36
+ def is_meta_command?(v)
37
+ meta_commands.include? v
38
+ end
39
+
40
+ def meta_commands
41
+ []
42
+ end
13
43
  end
@@ -1,3 +1,3 @@
1
1
  class TargetPractice
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: target_practice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: