git-trip 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.
Files changed (92) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +21 -0
  3. data/Manifest.txt +89 -0
  4. data/README.txt +60 -0
  5. data/Rakefile +31 -0
  6. data/bin/git-trip +0 -0
  7. data/doc/USAGE.txt +54 -0
  8. data/lib/core_ext/hash.rb +15 -0
  9. data/lib/git-trip.rb +23 -0
  10. data/lib/git-trip/errors.rb +22 -0
  11. data/lib/git-trip/gitter.rb +10 -0
  12. data/lib/git-trip/gitter/base.rb +18 -0
  13. data/lib/git-trip/gitter/dir.rb +32 -0
  14. data/lib/git-trip/gitter/uri.rb +40 -0
  15. data/lib/git-trip/paint_mode.rb +52 -0
  16. data/lib/git-trip/painter.rb +167 -0
  17. data/spec/core_ext/hash_spec.rb +25 -0
  18. data/spec/git-trip/errors_spec.rb +43 -0
  19. data/spec/git-trip/gitter/base_spec.rb +15 -0
  20. data/spec/git-trip/gitter/dir_spec.rb +37 -0
  21. data/spec/git-trip/gitter/uri_spec.rb +25 -0
  22. data/spec/git-trip/gitter_spec.rb +11 -0
  23. data/spec/git-trip/paint_mode_spec.rb +56 -0
  24. data/spec/git-trip/painter_spec.rb +173 -0
  25. data/spec/git_trip_spec.rb +23 -0
  26. data/spec/rcov.opts +1 -0
  27. data/spec/spec.opts +4 -0
  28. data/spec/spec_helper.rb +15 -0
  29. data/tasks/ditz.rake +42 -0
  30. data/tasks/docs.rake +68 -0
  31. data/tasks/gittrip.rake +63 -0
  32. data/tasks/rspec.rake +22 -0
  33. data/tasks/site.rake +48 -0
  34. data/tasks/util.rake +44 -0
  35. data/vendor/grit/History.txt +6 -0
  36. data/vendor/grit/Manifest.txt +53 -0
  37. data/vendor/grit/README.txt +213 -0
  38. data/vendor/grit/Rakefile +29 -0
  39. data/vendor/grit/grit.gemspec +16 -0
  40. data/vendor/grit/lib/grit.rb +37 -0
  41. data/vendor/grit/lib/grit/actor.rb +36 -0
  42. data/vendor/grit/lib/grit/blob.rb +117 -0
  43. data/vendor/grit/lib/grit/commit.rb +208 -0
  44. data/vendor/grit/lib/grit/config.rb +44 -0
  45. data/vendor/grit/lib/grit/diff.rb +70 -0
  46. data/vendor/grit/lib/grit/errors.rb +7 -0
  47. data/vendor/grit/lib/grit/git.rb +116 -0
  48. data/vendor/grit/lib/grit/index.rb +77 -0
  49. data/vendor/grit/lib/grit/lazy.rb +31 -0
  50. data/vendor/grit/lib/grit/ref.rb +110 -0
  51. data/vendor/grit/lib/grit/repo.rb +318 -0
  52. data/vendor/grit/lib/grit/tree.rb +99 -0
  53. data/vendor/grit/test/fixtures/blame +131 -0
  54. data/vendor/grit/test/fixtures/cat_file_blob +1 -0
  55. data/vendor/grit/test/fixtures/cat_file_blob_size +1 -0
  56. data/vendor/grit/test/fixtures/diff_2 +54 -0
  57. data/vendor/grit/test/fixtures/diff_2f +19 -0
  58. data/vendor/grit/test/fixtures/diff_f +15 -0
  59. data/vendor/grit/test/fixtures/diff_i +201 -0
  60. data/vendor/grit/test/fixtures/diff_mode_only +1152 -0
  61. data/vendor/grit/test/fixtures/diff_new_mode +17 -0
  62. data/vendor/grit/test/fixtures/diff_p +610 -0
  63. data/vendor/grit/test/fixtures/for_each_ref +0 -0
  64. data/vendor/grit/test/fixtures/for_each_ref_remotes +0 -0
  65. data/vendor/grit/test/fixtures/for_each_ref_tags +0 -0
  66. data/vendor/grit/test/fixtures/ls_tree_a +7 -0
  67. data/vendor/grit/test/fixtures/ls_tree_b +2 -0
  68. data/vendor/grit/test/fixtures/ls_tree_commit +3 -0
  69. data/vendor/grit/test/fixtures/rev_list +26 -0
  70. data/vendor/grit/test/fixtures/rev_list_count +655 -0
  71. data/vendor/grit/test/fixtures/rev_list_single +7 -0
  72. data/vendor/grit/test/fixtures/rev_parse +1 -0
  73. data/vendor/grit/test/fixtures/show_empty_commit +6 -0
  74. data/vendor/grit/test/fixtures/simple_config +2 -0
  75. data/vendor/grit/test/helper.rb +17 -0
  76. data/vendor/grit/test/profile.rb +21 -0
  77. data/vendor/grit/test/suite.rb +6 -0
  78. data/vendor/grit/test/test_actor.rb +35 -0
  79. data/vendor/grit/test/test_blob.rb +74 -0
  80. data/vendor/grit/test/test_commit.rb +182 -0
  81. data/vendor/grit/test/test_config.rb +58 -0
  82. data/vendor/grit/test/test_diff.rb +18 -0
  83. data/vendor/grit/test/test_git.rb +52 -0
  84. data/vendor/grit/test/test_head.rb +22 -0
  85. data/vendor/grit/test/test_real.rb +19 -0
  86. data/vendor/grit/test/test_reality.rb +17 -0
  87. data/vendor/grit/test/test_remote.rb +15 -0
  88. data/vendor/grit/test/test_repo.rb +278 -0
  89. data/vendor/grit/test/test_tag.rb +29 -0
  90. data/vendor/grit/test/test_tree.rb +91 -0
  91. metadata +179 -0
  92. metadata.gz.sig +0 -0
@@ -0,0 +1,167 @@
1
+ module GitTrip
2
+
3
+ # This does the work of creating a commit specific image.
4
+ class Painter
5
+ DEFAULTS = {
6
+ :format => 'png',
7
+ :header => false,
8
+ :label => false,
9
+ :style => 'horizontal',
10
+ :width => 50,
11
+ :height => 50
12
+ }
13
+
14
+ STYLES = %w{
15
+ montage
16
+ horizontal
17
+ vertical
18
+ }
19
+
20
+ attr_reader :canvas, :colors, :name, :picture
21
+
22
+ # Takes a single 40 character +sha+ string and an (optional)
23
+ # hash of +options+ (see DEFAULTS).
24
+ #
25
+ # +options+ can contain:
26
+ # * <tt>format</tt>: Image format; anything Magick::Image.new supports (ex. 'png', 'gif', etc).
27
+ # * <tt>header</tt>: If true, prints a header above the image, defaults to true; see +name+.
28
+ # * <tt>label</tt>: If true, the commit SHA will be included in the image; defaults to false.
29
+ # * <tt>name</tt>: The text to use above the commit image; only used if +header+ is true.
30
+ # * <tt>style</tt>: Generated image style; see STYLES.
31
+ # * <tt>width</tt>: Generated commit image width.
32
+ # * <tt>height</tt>: Generated commit image height.
33
+ def initialize(sha, options = {})
34
+ @options = DEFAULTS.merge(options)
35
+ raise Errors::RTFM unless sha.is_a?(String)
36
+ raise Errors::InvalidFormat unless Magick.formats.include?(@options[:format].upcase)
37
+ raise Errors::InvalidSHA if invalid_sha?(sha)
38
+ raise Errors::InvalidStyle if invalid_style?(@options[:style])
39
+ @sha = sha
40
+ @colors, @remainder = split_colors
41
+ @name = (@options[:name] || create_name)
42
+ @canvas = build_canvas
43
+ @picture = nil
44
+ end
45
+
46
+ # Paint a <tt>@picture</tt> based on <tt>@canvas</tt> and <tt>@options[:style]</tt>.
47
+ # Returns true or false based on the success of assigning <tt>@picture</tt>.
48
+ def paint!
49
+ # Need to set these locally, since <tt>Magick::ImageList#montage</tt>
50
+ # can't access instance variables in it's block, for some reason.
51
+ name = @name
52
+ header = @options[:header]
53
+ width = @options[:width]
54
+ height = @options[:height]
55
+ size = get_dimensions
56
+
57
+ montage = @canvas.montage do
58
+ self.geometry = Magick::Geometry.new(width, height)
59
+ self.title = name if header
60
+ self.tile = Magick::Geometry.new(size.first, size.last) if size
61
+ end
62
+
63
+ @picture = montage.flatten_images
64
+ @picture.format = @options[:format]
65
+ return (@picture ? true : false)
66
+ end
67
+
68
+ # Saves <tt>@picture</tt> to +location+ as '<tt>name</tt>.<tt>format</tt>'.
69
+ # Returns the <tt>@picture</tt> or nil upon failure.
70
+ #
71
+ # Example:
72
+ # painter = GitTrip::Painter.new(commit, :format => 'png')
73
+ # painter.paint!
74
+ # painter.save('/tmp', 'my_repo')
75
+ #
76
+ # Which would save the image as '/tmp/my_repo.png'
77
+ def save(location, name)
78
+ raise Errors::NoPicture unless @picture
79
+ full_path = File.expand_path(location)
80
+ FileUtils.mkpath(full_path) unless File.exists?(full_path)
81
+ @picture.write("#{location}/#{name}.#{@options[:format]}")
82
+ end
83
+
84
+ private
85
+
86
+ # Applies a +text+ string to a given +image+.
87
+ def apply_label(text, image)
88
+ image.composite(build_label(text),
89
+ Magick::CenterGravity,
90
+ Magick::HardLightCompositeOp)
91
+ end
92
+
93
+ # Builds a Magick::ImageList canvas for the <tt>@colors</tt>.
94
+ # This is also where the label is conditionally applied.
95
+ def build_canvas
96
+ canvas = Magick::ImageList.new
97
+ @colors.each do |color|
98
+ image = Magick::Image.new(@options[:width], @options[:height]) do
99
+ self.background_color = "\##{color}"
100
+ end
101
+ canvas << (@options[:label] ? apply_label(color, image) : image)
102
+ end
103
+ return canvas
104
+ end # of build_canvas
105
+
106
+ # Builds an image with the given +text+.
107
+ # TODO: Find a sane way of setting the pointsize.
108
+ # TODO: Allow custom font options.
109
+ def build_label(text)
110
+ shading = false
111
+
112
+ label = Magick::Image.new(@options[:width], @options[:height])
113
+ image = Magick::Draw.new
114
+ image.gravity = Magick::CenterGravity
115
+ image.pointsize = @options[:width] / 4
116
+ image.font = 'Helvetica'
117
+ image.font_weight = Magick::NormalWeight
118
+ image.stroke = 'none'
119
+ image.annotate(label, 0, 0, 0, 0, text)
120
+ label = label.shade(shading, 310, 30)
121
+
122
+ return label
123
+ end
124
+
125
+ # Generate a name based on the remaining 4 characters of the SHA.
126
+ # Returns the created name.
127
+ # Only called if <tt>@options[:name]</tt> is not given.
128
+ def create_name
129
+ colors = @colors
130
+ first = colors.sort_by{rand}.first.split('')[0..2].sort_by{rand}.to_s
131
+ last = colors.sort_by{rand}.last.split('')[0..2].sort_by{rand}.to_s
132
+ return "--- #{first}.#{@remainder}.#{last} ---"
133
+ end
134
+
135
+ # Returns an array of dimensions to be used in an ImageList#montage block.
136
+ # (ex. [4, 3])
137
+ def get_dimensions
138
+ case @options[:style]
139
+ when 'horizontal'
140
+ [@colors.size, 1]
141
+ when 'vertical'
142
+ [1, @colors.size]
143
+ end
144
+ end
145
+
146
+ # Returns true if +sha+ is invalid.
147
+ # TODO: Probably a better way of validating a SHA.
148
+ def invalid_sha?(sha)
149
+ sha.size != 40
150
+ end
151
+
152
+ # Returns true if +style+ is not in STYLES.
153
+ def invalid_style?(style)
154
+ return true unless STYLES.include?(style)
155
+ end
156
+
157
+ # Returns a 6 element array of RGB color codes, and the
158
+ # remaining 4 characters (as a string).
159
+ def split_colors
160
+ array = []
161
+ remainder = @sha.split('') # Yes, it's not the remainder now, but it will be at the return statement.
162
+ 6.times { array << remainder.slice!(0, 6).to_s }
163
+ return array, remainder.to_s
164
+ end
165
+ end # of Painter
166
+
167
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Hash, 'core extensions' do
4
+ before(:each) do
5
+ @hash = {
6
+ 'key1' => 'val1',
7
+ 'key2' => [1, 2, 3],
8
+ 'key3' => {:a => 1, :b => 2}
9
+ }
10
+ end
11
+
12
+ it "should symbolize keys" do
13
+ symbol_keys = @hash.symbolize_keys
14
+ symbol_keys.each_key do |key|
15
+ key.should be_a_kind_of(Symbol)
16
+ end
17
+ end
18
+
19
+ it "should symbolize keys destructively" do
20
+ @hash.symbolize_keys!
21
+ @hash.each_key do |key|
22
+ key.should be_a_kind_of(Symbol)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Errors do
4
+ it "should define DirNotFound" do
5
+ Errors::DirNotFound.should be_a_kind_of(Class)
6
+ end
7
+
8
+ it "should define InvalidFormat" do
9
+ Errors::InvalidFormat.should be_a_kind_of(Class)
10
+ end
11
+
12
+ it "should define InvalidGitRepo" do
13
+ Errors::InvalidGitRepo.should be_a_kind_of(Class)
14
+ end
15
+
16
+ it "should define InvalidMode" do
17
+ Errors::InvalidMode.should be_a_kind_of(Class)
18
+ end
19
+
20
+ it "should define InvalidPicture" do
21
+ Errors::InvalidPicture.should be_a_kind_of(Class)
22
+ end
23
+
24
+ it "should define InvalidSHA" do
25
+ Errors::InvalidSHA.should be_a_kind_of(Class)
26
+ end
27
+
28
+ it "should define InvalidStyle" do
29
+ Errors::InvalidStyle.should be_a_kind_of(Class)
30
+ end
31
+
32
+ it "should define NoCommits" do
33
+ Errors::NoCommits.should be_a_kind_of(Class)
34
+ end
35
+
36
+ it "should define NoPicture" do
37
+ Errors::NoPicture.should be_a_kind_of(Class)
38
+ end
39
+
40
+ it "should define RTFM" do
41
+ Errors::RTFM.should be_a_kind_of(Class)
42
+ end
43
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Gitter::Base do
4
+ before(:each) do
5
+ @commits = %w{
6
+ ruby is fucking awesome word to your mother
7
+ }.map { |text| Digest::SHA1.hexdigest(text) }
8
+ @repo = mock(Gitter::Base)
9
+ @repo.stub!(:commits).and_return(@commits)
10
+ end
11
+
12
+ it "should return an array of commit SHAs" do
13
+ @repo.commits.should be_instance_of(Array)
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Gitter::Dir do
4
+ before(:each) do
5
+ # This is a test git repository.
6
+ @dir = File.expand_path(File.dirname(__FILE__) + '/../../../sandbox')
7
+ @repo = Gitter::Dir.new(@dir)
8
+ end
9
+
10
+ it "should read a repository from a directory" do
11
+ @repo.should be_a_kind_of(Gitter::Dir)
12
+ end
13
+
14
+ it "should raise Errors::DirNotFound" do
15
+ lambda { Gitter::Dir.new('/not/a/real/dir') }.should raise_error(Errors::DirNotFound)
16
+ end
17
+
18
+ it "should raise Grit::InvalidGitRepositoryError" do
19
+ lambda do
20
+ Gitter::Dir.new(File.dirname(__FILE__))
21
+ end.should raise_error(Grit::InvalidGitRepositoryError)
22
+ end
23
+
24
+ it "should return an array of commit SHAs" do
25
+ @repo = Gitter::Dir.new(@dir)
26
+ @repo.commits.should_not be_empty
27
+ end
28
+
29
+ it "should iterate the commits" do
30
+ @repo.each_commit do |c|
31
+ c.should be_instance_of(String)
32
+ c.size.should eql(40) # size of a SHA1
33
+ end
34
+ end
35
+
36
+ it "should return the author of a commit"
37
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Gitter::URI do
4
+ before(:each) do
5
+ @uri = 'http://github.com/api/v1/json/Oshuma/git-trip/commits/master'
6
+ @repo = Gitter::URI.new(@uri)
7
+ end
8
+
9
+ it "should read a repository from a URI" do
10
+ @repo.should be_a_kind_of(Gitter::URI)
11
+ end
12
+
13
+ it "should raise Errors::InvalidFormat" do
14
+ lambda do
15
+ Gitter::URI.new(@uri, :format => 'invalid')
16
+ end.should raise_error(Errors::InvalidFormat)
17
+ end
18
+
19
+ it "should raise Errors::InvalidURI" do
20
+ lambda { Gitter::URI.new('bogus URI') }.should raise_error(Errors::InvalidURI)
21
+ end
22
+
23
+ it "should return an array of commit SHAs"
24
+ it "should return the author of a commit"
25
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Gitter, '(module)' do
4
+ it "should include Gitter::Dir" do
5
+ Gitter::Dir.should be_a_kind_of(Class)
6
+ end
7
+
8
+ it "should include Gitter::URI" do
9
+ Gitter::URI.should be_a_kind_of(Class)
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe PaintMode do
4
+ before(:each) do
5
+ @image = Magick::Image.new(5, 5)
6
+ @mode = PaintMode.new(@image, :blend)
7
+ end
8
+
9
+ it "should instantiate" do
10
+ @mode.should be_instance_of(PaintMode)
11
+ end
12
+
13
+ it "should raise ArgumentError" do
14
+ lambda { PaintMode.new }.should raise_error(ArgumentError)
15
+ end
16
+
17
+ it "should raise Errors::InvalidPicture" do
18
+ lambda do
19
+ PaintMode.new('not a picture', :blend)
20
+ end.should raise_error(Errors::InvalidPicture)
21
+ end
22
+
23
+ it "should raise Errors::InvalidMode" do
24
+ lambda do
25
+ PaintMode.new(@image, :invalid_mode)
26
+ end.should raise_error(Errors::InvalidMode)
27
+ end
28
+
29
+ it "should allow mode as symbol" do
30
+ PaintMode.new(@image, :blend).should be_instance_of(PaintMode)
31
+ end
32
+
33
+ it "should allow mode as string" do
34
+ PaintMode.new(@image, 'blend').should be_instance_of(PaintMode)
35
+ end
36
+
37
+ it "should define MODES" do
38
+ PaintMode::MODES.should be_instance_of(Array)
39
+ end
40
+
41
+ it "should have a picture accessor" do
42
+ @mode.picture.should be_instance_of(Magick::Image)
43
+ end
44
+
45
+ it "should blend" do
46
+ PaintMode.new(@image, :blend).picture.should be_instance_of(Magick::Image)
47
+ end
48
+
49
+ it "should pixel" do
50
+ PaintMode.new(@image, :pixel).picture.should be_instance_of(Magick::Image)
51
+ end
52
+
53
+ it "should radial" do
54
+ PaintMode.new(@image, :radial).picture.should be_instance_of(Magick::Image)
55
+ end
56
+ end
@@ -0,0 +1,173 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Painter do
4
+ before(:each) do
5
+ @commit = Digest::SHA1.hexdigest('ruby')
6
+ @painter = Painter.new(@commit)
7
+ end
8
+
9
+ it "should instantiate" do
10
+ @painter.should be_instance_of(Painter)
11
+ end
12
+
13
+ it "should raise Errors::InvalidSHA" do
14
+ lambda { Painter.new('not a valid sha') }.should raise_error(Errors::InvalidSHA)
15
+ end
16
+
17
+ it "should raise Errors::InvalidStyle" do
18
+ lambda do
19
+ Painter.new(@commit, :style => 'invalid')
20
+ end.should raise_error(Errors::InvalidStyle)
21
+ end
22
+
23
+ it "should raise Errors::RTFM" do
24
+ lambda { Painter.new(5) }.should raise_error(Errors::RTFM)
25
+ end
26
+
27
+ it "should define DEFAULTS" do
28
+ Painter::DEFAULTS.should be_instance_of(Hash)
29
+ end
30
+
31
+ it "should define STYLES" do
32
+ Painter::STYLES.should be_instance_of(Array)
33
+ end
34
+
35
+ it "should build a canvas" do
36
+ @painter.canvas.should be_instance_of(Magick::ImageList)
37
+ end
38
+
39
+ it "should set default width" do
40
+ options = @painter.instance_variable_get(:@options)
41
+ options[:width].should eql(50)
42
+ end
43
+
44
+ it "should allow a custom width" do
45
+ @painter = Painter.new(@commit, :width => 25)
46
+ options = @painter.instance_variable_get(:@options)
47
+ options[:width].should eql(25)
48
+ end
49
+
50
+ it "should set default height" do
51
+ options = @painter.instance_variable_get(:@options)
52
+ options[:height].should eql(50)
53
+ end
54
+
55
+ it "should allow a custom height" do
56
+ @painter = Painter.new(@commit, :height => 25)
57
+ options = @painter.instance_variable_get(:@options)
58
+ options[:height].should eql(25)
59
+ end
60
+
61
+ it "should set default style" do
62
+ options = @painter.instance_variable_get(:@options)
63
+ options[:style].should_not be_nil
64
+ end
65
+
66
+ it "should allow a horizontal style" do
67
+ @painter = Painter.new(@commit, :style => 'horizontal')
68
+ options = @painter.instance_variable_get(:@options)
69
+ options[:style].should eql('horizontal')
70
+ end
71
+
72
+ it "should allow a vertical style" do
73
+ @painter = Painter.new(@commit, :style => 'vertical')
74
+ options = @painter.instance_variable_get(:@options)
75
+ options[:style].should eql('vertical')
76
+ end
77
+
78
+ it "should allow a montage style" do
79
+ @painter = Painter.new(@commit, :style => 'montage')
80
+ options = @painter.instance_variable_get(:@options)
81
+ options[:style].should eql('montage')
82
+ end
83
+
84
+ it "should return an array of 6 RGB color codes" do
85
+ @painter.colors.size.should eql(6)
86
+ end
87
+
88
+ it "should have 6 characters per color" do
89
+ @painter.colors.each do |color|
90
+ color.size.should eql(6)
91
+ end
92
+ end
93
+
94
+ it "should have proper colors for it's SHA and remaining 4 characters" do
95
+ sha = @painter.colors.to_s + @commit[-4, 4]
96
+ sha.should eql(@commit)
97
+ end
98
+
99
+ it "should accept a custom size" do
100
+ Painter.new(@commit, :size => [25, 25]).should be_instance_of(Painter)
101
+ end
102
+
103
+ it "should paint a montage image" do
104
+ @painter.paint!.should_not be_false
105
+ @painter.picture.should be_instance_of(Magick::Image)
106
+ end
107
+
108
+ it "should paint a horizontal image" do
109
+ @painter = Painter.new(@commit, :style => 'horizontal')
110
+ @painter.paint!.should_not be_false
111
+ @painter.picture.should be_instance_of(Magick::Image)
112
+ end
113
+
114
+ it "should paint a vertical image" do
115
+ @painter = Painter.new(@commit, :style => 'vertical')
116
+ @painter.paint!.should_not be_false
117
+ @painter.picture.should be_instance_of(Magick::Image)
118
+ end
119
+
120
+ it "should create an image with commits color labels" do
121
+ @painter = Painter.new(@commit, :label => true)
122
+ @painter.paint!.should_not be_false
123
+ @painter.picture.should be_instance_of(Magick::Image)
124
+ end
125
+
126
+ it "should have a name" do
127
+ @painter.name.should_not be_nil
128
+ @painter.name.should be_instance_of(String)
129
+ end
130
+
131
+ it "should allow a custom name" do
132
+ @painter = Painter.new(@commit, :name => 'Awesome')
133
+ @painter.name.should eql('Awesome')
134
+ end
135
+
136
+ it "should allow a custom header option" do
137
+ @painter = Painter.new(@commit, :header => false)
138
+ options = @painter.instance_variable_get(:@options)
139
+ options[:header].should be_false
140
+ end
141
+
142
+ it "should allow custom format option" do
143
+ @painter = Painter.new(@commit, :format => 'jpg')
144
+ options = @painter.instance_variable_get(:@options)
145
+ options[:format].should eql('jpg')
146
+ @painter.paint!
147
+ @painter.picture.should be_instance_of(Magick::Image)
148
+ end
149
+
150
+ it "should raise Errors::InvalidFormat" do
151
+ lambda do
152
+ @painter = Painter.new(@commit, :format => 'some shit')
153
+ end.should raise_error(Errors::InvalidFormat)
154
+ end
155
+
156
+ it "should raise Errors::NoPicture" do
157
+ lambda do
158
+ @painter.save('/tmp', 'no picture')
159
+ end.should raise_error(Errors::NoPicture)
160
+ end
161
+
162
+ # Yes, this spec sucks.
163
+ it "should save the picture" do
164
+ test_path = File.expand_path('./sandbox/')
165
+ test_name = 'git-trip-test'
166
+ test_file = File.join(test_path, "#{test_name}.png")
167
+ File.delete(test_file) if File.exists?(test_file)
168
+ @painter.paint!
169
+ @painter.save(test_path, test_name).should be_instance_of(Magick::Image)
170
+ File.exists?(test_file).should be_true
171
+ File.delete(test_file) if File.exists?(test_file)
172
+ end
173
+ end