swdyh-gisty 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.
@@ -0,0 +1,159 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require "test/unit"
3
+ require 'pp'
4
+ require 'rr'
5
+
6
+ class GistyTest < Test::Unit::TestCase
7
+ include RR::Adapters::TestUnit
8
+
9
+ def setup
10
+ @gisty_dir = Pathname.new('tmp').realpath.join('gists')
11
+ @gisty = Gisty.new @gisty_dir, 'foo', 'bar'
12
+ stub_open_uri!
13
+ stub_kernel_system!
14
+ end
15
+
16
+ def teardown
17
+ FileUtils.rm_rf @gisty_dir
18
+ end
19
+
20
+ def stub_open_uri!
21
+ stub(OpenURI).open_uri do |uri|
22
+ filename = uri.to_s.split('/').last.gsub(/[&?=]/, '_')
23
+ path = File.join File.dirname(__FILE__), 'fixtures', filename
24
+ open path
25
+ end
26
+ end
27
+
28
+ def stub_kernel_system!
29
+ stub(Kernel).system do |cmd|
30
+ # puts "* '#{cmd}' *"
31
+ case cmd
32
+ when /^git clone/
33
+ id = cmd.split(/[:.]/)[-2]
34
+ system "mkdir -p #{id}"
35
+ system "touch #{File.join(id, id)}"
36
+ else
37
+ end
38
+ end
39
+ end
40
+
41
+ def stub_post_form! dummy = 'http://gist.github.com/111111'
42
+ stub(Net::HTTP).post_form do |uri, opt|
43
+ { 'Location' => dummy }
44
+ end
45
+ end
46
+
47
+ def test_extract_ids
48
+ url = 'http://gist.github.com/swdyh?page=4'
49
+ ids = Gisty.extract_ids url
50
+ assert ids.include?("6938")
51
+ assert ids.include?("3668")
52
+ end
53
+
54
+ def test_extract
55
+ meta = Gisty.extract 'http://gist.github.com/30119'
56
+ assert_equal 'brianleroux', meta[:author]
57
+ assert_equal 4, meta[:files].size
58
+ end
59
+
60
+ def test_new
61
+ assert_instance_of Gisty, @gisty
62
+ end
63
+
64
+ def test_page_num
65
+ assert_equal 2, @gisty.page_num
66
+ end
67
+
68
+ def test_page_urls
69
+ urls = @gisty.page_urls
70
+ assert_equal 2, urls.size
71
+ assert urls.all? { |u| u.match(/page=\d/) }
72
+ end
73
+
74
+ def test_remote_ids
75
+ ids = @gisty.remote_ids
76
+ assert_equal 19, ids.size
77
+ assert ids.include?('7205')
78
+ assert ids.include?('bc82698ab357bd8bb433')
79
+ end
80
+
81
+ def test_clone
82
+ id = @gisty.remote_ids.first
83
+ pn = @gisty_dir.join id
84
+ @gisty.clone id
85
+ end
86
+
87
+ def test_list
88
+ ids = @gisty.remote_ids
89
+ @gisty.clone ids[0]
90
+ @gisty.clone ids[1]
91
+ list = @gisty.list.map { |i| i.first }
92
+ assert list.include?(ids[0])
93
+ assert list.include?(ids[1])
94
+ end
95
+
96
+ def test_delete
97
+ id = '11111'
98
+ pn = @gisty_dir.join id
99
+ FileUtils.mkdir(pn)
100
+ @gisty.delete id
101
+ assert !pn.exist?
102
+ end
103
+
104
+ def test_sync
105
+ ids = @gisty.remote_ids
106
+ assert !ids.all? { |i| @gisty_dir.join(i).exist? }
107
+ @gisty.sync
108
+ assert ids.all? { |i| @gisty_dir.join(i).exist? }
109
+ end
110
+
111
+ def test_sync_delete
112
+ id = '12345'
113
+ assert !@gisty.remote_ids.include?(id)
114
+ @gisty.clone id
115
+ assert @gisty_dir.join(id).exist?
116
+ @gisty.sync true
117
+ assert !@gisty_dir.join(id).exist?
118
+ end
119
+
120
+ def test_build_params
121
+ g = Gisty.new @gisty_dir
122
+ path = File.join('test', 'fixtures', 'foo.user.js')
123
+ params = g.build_params path
124
+
125
+ assert_equal '.js', params['file_ext[gistfile1]']
126
+ assert_equal 'foo.user.js', params['file_name[gistfile1]']
127
+ assert_equal "// foo.user.js\n", params['file_contents[gistfile1]']
128
+ end
129
+
130
+ def test_build_params_multi
131
+ g = Gisty.new @gisty_dir
132
+ path1 = File.join('test', 'fixtures', 'foo.user.js')
133
+ path2 = File.join('test', 'fixtures', 'bar.user.js')
134
+ params = g.build_params [path1, path2]
135
+
136
+ assert_equal '.js', params['file_ext[gistfile1]']
137
+ assert_equal 'foo.user.js', params['file_name[gistfile1]']
138
+ assert_equal "// foo.user.js\n", params['file_contents[gistfile1]']
139
+ assert_equal '.js', params['file_ext[gistfile2]']
140
+ assert_equal 'bar.user.js', params['file_name[gistfile2]']
141
+ assert_equal "// bar.user.js\n", params['file_contents[gistfile2]']
142
+ end
143
+
144
+ def test_create
145
+ stub_post_form!
146
+ g = Gisty.new @gisty_dir
147
+ path = File.join('test', 'fixtures', 'foo.user.js')
148
+ g.create(path)
149
+ end
150
+
151
+ def test_create_multi
152
+ stub_post_form!
153
+ g = Gisty.new @gisty_dir
154
+ path1 = File.join('test', 'fixtures', 'foo.user.js')
155
+ path2 = File.join('test', 'fixtures', 'bar.user.js')
156
+ g.create([path1, path2])
157
+ end
158
+ end
159
+
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/gisty'
3
+
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swdyh-gisty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - swdyh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-06 00:00:00 -08:00
13
+ default_executable: gisty
14
+ dependencies: []
15
+
16
+ description: yet another command line client for gist
17
+ email: http://mailhide.recaptcha.net/d?k=01AhB7crgrlHptVaYRD0oPwA==&c=L_iqOZrGmo6hcGpPTFg1QYnjr-WpAStyQ4Y8ShfgOHs=
18
+ executables:
19
+ - gisty
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - README.rdoc
26
+ - Rakefile
27
+ - bin/gisty
28
+ - test/fixtures
29
+ - test/fixtures/24835
30
+ - test/fixtures/30119
31
+ - test/fixtures/bar.user.js
32
+ - test/fixtures/foo.user.js
33
+ - test/fixtures/mine_login_foo_token_bar
34
+ - test/fixtures/mine_page_1_login_foo_token_bar
35
+ - test/fixtures/mine_page_2_login_foo_token_bar
36
+ - test/fixtures/swdyh
37
+ - test/fixtures/swdyh_page_4
38
+ - test/gisty_test.rb
39
+ - test/test_helper.rb
40
+ - lib/gisty.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/swdyh/gisty/tree/master
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --title
46
+ - gisty documentation
47
+ - --charset
48
+ - utf-8
49
+ - --opname
50
+ - index.html
51
+ - --line-numbers
52
+ - --main
53
+ - README.rdoc
54
+ - --inline-source
55
+ - --exclude
56
+ - ^(examples|extras)/
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project: gisty
74
+ rubygems_version: 1.2.0
75
+ signing_key:
76
+ specification_version: 2
77
+ summary: yet another command line client for gist
78
+ test_files:
79
+ - test/gisty_test.rb