graffle 0.1.8 → 0.1.9

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.
Files changed (44) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +22 -11
  3. data/README.txt +2 -2
  4. data/Rakefile.hoe +2 -1
  5. data/design-notes/graphical-tests-for-rails-objects.graffle +644 -0
  6. data/examples/objects with notes.expected +5 -0
  7. data/examples/objects with notes.graffle +338 -0
  8. data/examples/objects with notes.rb +42 -0
  9. data/examples/rails-workflow-test.expected +1 -1
  10. data/examples/rails-workflow-test.graffle/data.plist +86 -7
  11. data/examples/rails-workflow-test.rb +11 -9
  12. data/graffle.tmproj +82 -190
  13. data/lib/graffle.rb +19 -2
  14. data/lib/graffle/point.rb +1 -2
  15. data/lib/graffle/stereotypes.rb +62 -16
  16. data/lib/graffle/version.rb +1 -1
  17. data/lib/graphical_tests_for_rails.rb +8 -5
  18. data/lib/graphical_tests_for_rails/graphic-volunteers.rb +75 -0
  19. data/lib/graphical_tests_for_rails/orderings.rb +90 -84
  20. data/lib/graphical_tests_for_rails/picture-appliers.rb +225 -0
  21. data/lib/graphical_tests_for_rails/text-appliers.rb +135 -0
  22. data/lib/graphical_tests_for_rails/volunteer-pool.rb +115 -0
  23. data/test/abstract-graphic-tests.rb +48 -0
  24. data/test/document-tests.rb +5 -5
  25. data/test/examples-tests.rb +42 -0
  26. data/test/graphical_tests_for_rails/{graphic-interpreter-tests.rb → deprecated-graphic-interpreter-tests.rb} +11 -21
  27. data/test/graphical_tests_for_rails/graphic-volunteer-tests.rb +218 -0
  28. data/test/graphical_tests_for_rails/in-workflow-order-tests.rb +1 -1
  29. data/test/graphical_tests_for_rails/picture-applier-tests.rb +215 -0
  30. data/test/graphical_tests_for_rails/{text-interpreter-tests.rb → text-applier-tests.rb} +17 -3
  31. data/test/graphical_tests_for_rails/util.rb +16 -0
  32. data/test/line-graphic-tests.rb +9 -1
  33. data/test/note-tests.rb +62 -0
  34. data/test/{graffle-file-types → sample-files}/as-a-package.graffle/data.plist +0 -0
  35. data/test/{graffle-file-types → sample-files}/as-a-package.graffle/image1.png +0 -0
  36. data/test/{graffle-file-types → sample-files}/as-a-package.graffle/image2.png +0 -0
  37. data/test/{graffle-file-types → sample-files}/as-a-package.graffle/image3.png +0 -0
  38. data/test/{graffle-file-types → sample-files}/multiple-canvases.graffle +0 -0
  39. data/test/{graffle-file-types → sample-files}/opening-tests.rb +9 -4
  40. data/test/{graffle-file-types → sample-files}/two-boxes-and-a-line.graffle +0 -0
  41. data/test/shaped-graphic-tests.rb +2 -3
  42. metadata +42 -18
  43. data/lib/graphical_tests_for_rails/interpreters.rb +0 -147
  44. data/test/tests-of-examples/workflow-slowtests.rb +0 -19
@@ -53,4 +53,52 @@ class TestAbstractGraphics < Test::Unit::TestCase
53
53
  assert_false(equal_line.before?(graphic))
54
54
  assert_false(graphic.before?(equal_line))
55
55
  end
56
+
57
+ rtf = %Q{
58
+ | {\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf420
59
+ | {\fonttbl\f0\fswiss\fcharset77 Helvetica;}
60
+ | {\colortbl;\red255\green255\blue255;}
61
+ | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
62
+ |
63
+ | \f0\fs24 \cf0 line\
64
+ | label\
65
+ | note}}.trim('|')
66
+
67
+
68
+ def test_abstract_graphics_can_be_built_with_notes
69
+ graphic = abstract_graphic {
70
+ with_notes "hi"
71
+ }
72
+
73
+ assert_equal("hi", graphic['Notes'])
74
+ assert_equal("hi", graphic.notes)
75
+
76
+ end
77
+
78
+
79
+ def test_abstract_graphics_do_not_have_to_have_notes
80
+ assert_false(abstract_graphic.has_notes?)
81
+ end
82
+
83
+ def test_for_some_purposes_its_convenient_to_have_null_notes
84
+ assert_equal([], abstract_graphic.notes.as_lines)
85
+ end
86
+
87
+
88
+ def test_abstract_graphics_stereotype_their_notes
89
+ s = sheet {
90
+ with shaped_graphic {
91
+ graffle_id_is 333
92
+ with_note "foo"
93
+ }
94
+ with line_graphic { graffle_id_is 44 } # Check that this doesn't blow up
95
+ }
96
+
97
+ # buid correct structure, but without anything stereotyped.
98
+ s = Plist.parse_xml(s.to_plist)
99
+ Sheet.takes_on(s)
100
+
101
+ assert_true(s.find_by_id(333).note.behaves_like?(Graffle::Note))
102
+ end
103
+
56
104
  end
@@ -74,13 +74,13 @@ class TestCaseGraffleDocumentParsing < Test::Unit::TestCase
74
74
  }.to_plist
75
75
 
76
76
  def test_parsed_file_behaves_like_whole_graffle_doc
77
- graffle = Graffle.parse(MultiSheetFormat)
77
+ graffle = Graffle.parse_xml(MultiSheetFormat)
78
78
  assert_true(graffle.behaves_like?(Graffle::Document))
79
79
  end
80
80
 
81
81
 
82
82
  def test_can_fetch_components_from_plist
83
- graffle = Graffle.parse(MultiSheetFormat)
83
+ graffle = Graffle.parse_xml(MultiSheetFormat)
84
84
  assert_equal(2, graffle.sheets.length)
85
85
  assert_equal('1', graffle.sheets[0]['SheetTitle']);
86
86
  assert_true(graffle.sheets[0].behaves_like?(Graffle::Sheet))
@@ -98,7 +98,7 @@ class TestCaseGraffleDocumentParsing < Test::Unit::TestCase
98
98
  }.to_plist
99
99
 
100
100
  def test_some_graffle_documents_do_not_have_an_explicit_sheet
101
- graffle = Graffle.parse(ImplicitSheetFormat)
101
+ graffle = Graffle.parse_xml(ImplicitSheetFormat)
102
102
 
103
103
  assert_equal(1, graffle.sheets.length)
104
104
  assert_true(graffle.sheets[0].behaves_like?(Graffle::Sheet))
@@ -107,10 +107,10 @@ class TestCaseGraffleDocumentParsing < Test::Unit::TestCase
107
107
  end
108
108
 
109
109
  def test_getting_first_sheet_only
110
- graffle = Graffle.parse(ImplicitSheetFormat)
110
+ graffle = Graffle.parse_xml(ImplicitSheetFormat)
111
111
  assert_true(graffle.first_sheet.behaves_like?(Graffle::Sheet))
112
112
 
113
- graffle = Graffle.parse(MultiSheetFormat)
113
+ graffle = Graffle.parse_xml(MultiSheetFormat)
114
114
  assert_true(graffle.first_sheet.behaves_like?(Graffle::Sheet))
115
115
  end
116
116
 
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Brian Marick on 2007-07-19.
4
+ # Copyright (c) 2007. All rights reserved.
5
+
6
+ require "set-standalone-test-paths.rb" unless $started_from_rakefile
7
+ require "test/unit"
8
+ require 's4t-utils'
9
+ include S4tUtils
10
+
11
+
12
+ class TestThatExamplesWork < Test::Unit::TestCase
13
+ EXAMPLES_HOME = "#{PACKAGE_ROOT}/examples"
14
+
15
+ def self.make_tests
16
+ Dir.chdir(EXAMPLES_HOME) do
17
+ Dir["*.rb"].collect { |e| e.sub(/\.rb$/,'') }.each do | example |
18
+ make_one_test(example)
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.make_one_test(name)
24
+ self.send(:define_method, test_message(name), lambda {
25
+ Dir.chdir(EXAMPLES_HOME) do
26
+ system "ruby '#{name}.rb' > '#{name}.actual' 2>&1"
27
+ system("diff '#{name}.expected' '#{name}.actual'")
28
+ assert_equal(0, $?)
29
+ system "rm '#{name}'.actual" if $? == 0
30
+ end
31
+ })
32
+ end
33
+
34
+
35
+ def self.test_message(name)
36
+ 'test_' + name.gsub(/\s+|-|\./, '_')
37
+ end
38
+
39
+
40
+ make_tests
41
+
42
+ end
@@ -11,35 +11,25 @@ require "../set-standalone-test-paths.rb" unless $started_from_rakefile
11
11
 
12
12
  require 'extensions/string'
13
13
  require 'graphical_tests_for_rails'
14
+ require 'test/graphical_tests_for_rails/util'
14
15
 
15
16
 
16
17
  class GraphicInterpreterTest < Test::Unit::TestCase
17
18
  include Graffle::Builders
18
19
  include GraphicalTestsForRails
19
20
 
20
- class CommandRecorder
21
- attr_reader :record
22
- def initialize
23
- @record = []
24
- end
25
-
26
- def method_missing(message, *args)
27
- @record << "#{message}(" + args.collect { | a | a.inspect }.join(", ") + ')'
28
- end
29
- end
30
-
31
21
  def two_graphics
32
22
  s = sheet {
33
23
  with line_label {
34
24
  for_line 1
35
- with_text 'produce "argument"'
25
+ with_content 'produce "argument"'
36
26
  }
37
27
  with line_graphic {
38
28
  graffle_id_is 1
39
29
  }
40
30
  with shaped_graphic {
41
31
  graffle_id_is 2
42
- with_text "SIGNUP"
32
+ with_content "SIGNUP"
43
33
  }
44
34
  }
45
35
 
@@ -55,7 +45,7 @@ class GraphicInterpreterTest < Test::Unit::TestCase
55
45
  def test_interpreter_applies_strategies
56
46
  interpreter = GraphicInterpreter.new(two_graphics,
57
47
  'line labels' => ArgsFromQuotedText.new,
58
- 'shaped graphic text' => TextIsNameOfPage.new('assert_on_page'))
48
+ 'shaped graphic text' => TextAsNameOfPage.new('assert_on_page'))
59
49
  assert_commands_produced(['produce("argument")', 'assert_on_page("signup")'],
60
50
  interpreter)
61
51
  end
@@ -72,7 +62,7 @@ class GraphicInterpreterTest < Test::Unit::TestCase
72
62
 
73
63
  def test_interpreter_annotates_test_failures_with_log
74
64
  interpreter = GraphicInterpreter.new(two_graphics,
75
- 'shaped graphic text' => TextIsNameOfPage.new('assert_that_fails'))
65
+ 'shaped graphic text' => TextAsNameOfPage.new('assert_that_fails'))
76
66
  interpreter.run_against(self)
77
67
  flunk("Should be unreached.")
78
68
  rescue Test::Unit::AssertionFailedError => e
@@ -92,25 +82,25 @@ class GraphicInterpreterTest < Test::Unit::TestCase
92
82
  s = sheet {
93
83
  with line_label {
94
84
  for_line 1
95
- with_text 'label'
85
+ with_content 'label'
96
86
  }
97
87
  with line_graphic {
98
88
  graffle_id_is 1
99
89
  }
100
90
  with shaped_graphic {
101
91
  graffle_id_is 2
102
- with_text "signup "
92
+ with_content "signup "
103
93
  }
104
94
  with line_label {
105
95
  for_line 11
106
- with_text 'waiting on a "friend"... '
96
+ with_content 'waiting on a "friend"... '
107
97
  }
108
98
  with line_graphic {
109
99
  graffle_id_is 11
110
100
  }
111
101
  with shaped_graphic {
112
102
  graffle_id_is 22
113
- with_text "time passes..."
103
+ with_content "time passes..."
114
104
  }
115
105
  }
116
106
 
@@ -119,8 +109,8 @@ class GraphicInterpreterTest < Test::Unit::TestCase
119
109
 
120
110
  def test_ellipses_strategy_overrides_others
121
111
  interpreter = GraphicInterpreter.new(four_graphics_including_ellipses,
122
- 'line labels' => TextIsNameOfPage.new("line_here"),
123
- 'shaped graphic text' => TextIsNameOfPage.new('shape_here'),
112
+ 'line labels' => TextAsNameOfPage.new("line_here"),
113
+ 'shaped graphic text' => TextAsNameOfPage.new('shape_here'),
124
114
  'text...' => ArgsFromQuotedText.new)
125
115
  assert_commands_produced(['line_here("label")', 'shape_here("signup")',
126
116
  'waiting_on_a("friend")', 'time_passes()'],
@@ -0,0 +1,218 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created by Brian Marick on 2007-07-20.
4
+ # Copyright (c) 2007. All rights reserved.
5
+
6
+ require 'test/unit'
7
+ require 's4t-utils'
8
+ include S4tUtils
9
+
10
+ require "../set-standalone-test-paths.rb" unless $started_from_rakefile
11
+
12
+ require 'graphical_tests_for_rails/graphic-volunteers'
13
+ require 'graphical_tests_for_rails/volunteer-pool'
14
+ require 'graffle'
15
+
16
+ class GraphicVolunteerTest < Test::Unit::TestCase
17
+ include GraphicalTestsForRails
18
+ include Graffle::Builders
19
+
20
+ def setup
21
+ @pool = GraphicVolunteerPool.new
22
+ end
23
+
24
+ def test_untrained_volunteer_wants_to_handle_everything
25
+ assert_true(GraphicVolunteer.new('irrelevant').likes?(Object.new))
26
+ end
27
+
28
+ def test_untrained_volunteer_does_not_even_try_to_extract_lines
29
+ assert_equal([], GraphicVolunteer.new('irrelevent').extract_lines(Object.new))
30
+ end
31
+
32
+ # Trained volunteers will be fetched from the pool, then tested.
33
+
34
+ def test_volunteers_must_be_fetched_with_known_names
35
+ assert_raises(StandardError) {
36
+ @pool.mobilize_form_watcher('nothing')
37
+ }
38
+ end
39
+
40
+
41
+
42
+ def test_some_volunteers_go_for_shaped_graphic_content
43
+ volunteer = @pool.mobilize_form_watcher('shaped graphic content')
44
+
45
+ assert_false(volunteer.likes?(abstract_graphic))
46
+ assert_false(volunteer.likes?(shaped_graphic))
47
+ assert_false(volunteer.likes?(shaped_graphic { with_note "hello" }))
48
+ assert_true(volunteer.likes?(shaped_graphic { with_content "hello" }))
49
+ end
50
+
51
+ def test_those_volunteers_extract_only_shaped_graphic_content_lines
52
+ volunteer = @pool.mobilize_form_watcher('shaped graphic content')
53
+ graphic = shaped_graphic {
54
+ with_content "expected"
55
+ with_note "not expected"
56
+ }
57
+
58
+ assert_equal(["expected"], volunteer.extract_lines(graphic))
59
+ end
60
+
61
+ def test_som_volunteers_go_for_line_label_content
62
+ # Here are the pieces of the structure that matter:
63
+ empty_label = good_label = no_label = nil
64
+
65
+ s = sheet {
66
+ with label_without_text = line_label {
67
+ for_line 1
68
+ }
69
+ with label_with_fine_text = line_label {
70
+ for_line 2
71
+ with_content "hi"
72
+ }
73
+ with empty_label = line_graphic { graffle_id_is 1 }
74
+ with good_label = line_graphic { graffle_id_is 2 }
75
+ with no_label = line_graphic { graffle_id_is 3 }
76
+ }
77
+
78
+ volunteer = @pool.mobilize_form_watcher('line label content')
79
+
80
+ assert_false(volunteer.likes?(shaped_graphic { with_content 'foo' }))
81
+ assert_false(volunteer.likes?(empty_label))
82
+ assert_false(volunteer.likes?(no_label))
83
+ assert_true(volunteer.likes?(good_label))
84
+ end
85
+
86
+ def test_those_volunteers_extract_only_line_label_content_lines
87
+ volunteer = @pool.mobilize_form_watcher('line label content')
88
+
89
+ s = sheet {
90
+ with line_graphic {
91
+ graffle_id_is 1
92
+ }
93
+
94
+ with line_label {
95
+ for_line 1
96
+ with_content "expected"
97
+ with_note "not expected"
98
+ }
99
+ }
100
+
101
+ assert_equal(["expected"], volunteer.extract_lines(s.find_by_id(1)))
102
+ end
103
+
104
+
105
+ def test_some_volunteers_go_for_notes_attached_to_anything
106
+ # Here are the pieces of the structure that matter:
107
+ shaped_with_note = shaped_graphic {
108
+ graffle_id_is 1
109
+ with_note "this matches"
110
+ }
111
+ shaped_without_note = shaped_graphic {
112
+ graffle_id_is 2
113
+ with_content "this does not"
114
+ }
115
+ line_graphic_with_nothing = line_graphic
116
+ line_graphic_with_only_label_text = line_graphic {
117
+ # label added below.
118
+ graffle_id_is 999
119
+ }
120
+ line_graphic_with_note = line_graphic {
121
+ # label added below
122
+ graffle_id_is 888
123
+ }
124
+
125
+ s = sheet {
126
+ with shaped_with_note
127
+ with shaped_without_note
128
+ with line_graphic_with_nothing
129
+ with line_graphic_with_only_label_text
130
+ with line_graphic_with_note
131
+
132
+ with line_label {
133
+ for_line line_graphic_with_only_label_text.graffle_id
134
+ with_content "unmatching line label"
135
+ }
136
+ with line_label {
137
+ for_line line_graphic_with_note.graffle_id
138
+ with_note "matching line label - has note"
139
+ }
140
+ }
141
+
142
+ volunteer = @pool.mobilize_form_watcher('note')
143
+ assert_true(volunteer.likes?(shaped_with_note))
144
+ assert_false(volunteer.likes?(shaped_without_note))
145
+ assert_false(volunteer.likes?(line_graphic_with_nothing))
146
+ assert_false(volunteer.likes?(line_graphic_with_only_label_text))
147
+ assert_true(volunteer.likes?(line_graphic_with_note))
148
+ end
149
+
150
+ def test_those_volunteers_extract_only_note_lines
151
+ shaped_with_note = shaped_graphic { with_note "expected" }
152
+ line_with_label_note = line_graphic { graffle_id_is 1 } # label added later
153
+ line_with_own_note = line_graphic { with_note "expected"}
154
+ line_with_both = line_graphic {
155
+ graffle_id = 999
156
+ with_note "expected"
157
+ }
158
+
159
+ s = sheet {
160
+ with shaped_with_note
161
+ with line_with_label_note
162
+ with line_with_own_note
163
+ with line_with_both
164
+ with line_label {
165
+ for_line line_with_label_note.graffle_id
166
+ with_note "expected"
167
+ }
168
+ with line_label {
169
+ for_line line_with_both.graffle_id
170
+ with_note "NOT expected - line note takes precedence"
171
+ }
172
+ }
173
+
174
+ volunteer = @pool.mobilize_form_watcher('note')
175
+
176
+ assert_equal(["expected"], volunteer.extract_lines(shaped_with_note))
177
+ assert_equal(["expected"], volunteer.extract_lines(line_with_label_note))
178
+ assert_equal(["expected"], volunteer.extract_lines(line_with_own_note))
179
+ assert_equal(["expected"], volunteer.extract_lines(line_with_both))
180
+ end
181
+
182
+ #
183
+ # Content volunteers look at lines of text, not graphics.
184
+ # They don't extract lines, so that's not tested.
185
+ #
186
+
187
+ def test_some_content_volunteers_go_for_text_with_ellipses
188
+ volunteer = @pool.mobilize_content_watcher('text...')
189
+
190
+ assert_true(volunteer.likes?(["foo..."]))
191
+ assert_true(volunteer.likes?(["foo.."])) # allow typos
192
+ assert_true(volunteer.likes?(["foo...."]))
193
+ assert_true(volunteer.likes?(["foo.... "]))
194
+ assert_false(volunteer.likes?(["foo...b"]))
195
+ end
196
+
197
+ def test_some_content_volunteers_go_for_text_to_be_ignored
198
+ volunteer = @pool.mobilize_content_watcher('ignore')
199
+
200
+ assert_true(volunteer.likes?(["ignore"]))
201
+ assert_true(volunteer.likes?([" ignore "]))
202
+ assert_false(volunteer.likes?(["something else"]))
203
+ assert_true(volunteer.likes?(["something else", "ignore"]))
204
+ end
205
+
206
+ def test_content_volunteers_are_chained_after_form_volunteers
207
+ graphic_volunteer = @pool.mobilize_form_watcher('note')
208
+ text_volunteer = @pool.mobilize_content_watcher('text...')
209
+
210
+ g = shaped_graphic { with_note "no ellipses" }
211
+ assert_true(graphic_volunteer.likes?(g))
212
+ graphic_volunteer.next = text_volunteer
213
+ assert_false(graphic_volunteer.likes?(g))
214
+
215
+ assert_true(graphic_volunteer.likes?(shaped_graphic{ with_note "..."}))
216
+ end
217
+
218
+ end