ruby-traileraddict 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ module Test::Unit
2
+ # Used to fix a minor minitest/unit incompatibility in flexmock
3
+ AssertionFailedError = Class.new(StandardError)
4
+
5
+ class TestCase
6
+
7
+ def self.test(name, &block)
8
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
9
+ defined = instance_method(test_name) rescue false
10
+ raise "#{test_name} is already defined in #{self}" if defined
11
+ if block_given?
12
+ define_method(test_name, &block)
13
+ else
14
+ define_method(test_name) do
15
+ flunk "No implementation provided for #{name}"
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ def register_url_stubs
2
+ unless(TEST_LIVE_API)
3
+
4
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "search.txt")) do |file|
5
+ stub_request(:get, Regexp.new("http:\/\/www.traileraddict.com/search.*")).to_return(file)
6
+ end
7
+
8
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "api_response.txt")) do |file|
9
+ stub_request(:get, Regexp.new(TrailerAddict.base_api_url + ".*")).to_return(file)
10
+ end
11
+
12
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "example_com.txt")) do |file|
13
+ stub_request(:get, Regexp.new("http://example.com.*")).to_return(file)
14
+ end
15
+
16
+ stub_request(:get, 'http://thisisaurlthatdoesntexist.co.nz').to_return(:body => "", :status => 404, :headers => {'content-length' => 0})
17
+
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ TEST_LIVE_API = false
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+
6
+ unless(TEST_LIVE_API)
7
+ require 'webmock/test_unit'
8
+ include WebMock
9
+ end
10
+
11
+ require_files = []
12
+ require_files << File.join(File.dirname(__FILE__), '..', 'lib', 'ruby-traileraddict.rb')
13
+ require_files.concat Dir[File.join(File.dirname(__FILE__), 'setup', '*.rb')]
14
+
15
+ require_files.each do |file|
16
+ require File.expand_path(file)
17
+ end
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class TrailerAddictTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ register_url_stubs
7
+ end
8
+
9
+ test "should return base API url" do
10
+ assert_equal "http://api.traileraddict.com/", TrailerAddict.base_api_url
11
+ end
12
+
13
+ test "should return base search URL" do
14
+ assert_equal "http://www.traileraddict.com/search.php?q=", TrailerAddict.base_search_url
15
+ end
16
+
17
+ test "get_tag_for should raise ArgumentError if searchterm is not provided" do
18
+ assert_raises ArgumentError do
19
+ TrailerAddict.get_tag_for
20
+ end
21
+ end
22
+
23
+ test "get_tag_for should return tag for movie" do
24
+ assert_equal 'iron-man', TrailerAddict.get_tag_for("Iron Man")
25
+ end
26
+
27
+ test "api_call should raise ArgumentError if movie tag is not specified" do
28
+ assert_raises ArgumentError do
29
+ TrailerAddict.api_call
30
+ end
31
+ end
32
+
33
+ test "api_call should raise ArgumentError if movie tag is not a string" do
34
+ assert_raises ArgumentError do
35
+ TrailerAddict.api_call(1)
36
+ end
37
+ end
38
+
39
+ test "api_call should return response body" do
40
+ File.open(File.join(File.dirname(__FILE__), "..", "fixtures", "api_response.txt")) do |file|
41
+ expected_response = file.read
42
+ assert expected_response.include?(TrailerAddict.api_call("iron-man"))
43
+ end
44
+ end
45
+
46
+ test "get_trailer_embed_code should raise ArgumentError if movie title not supplied" do
47
+ assert_raises ArgumentError do
48
+ TrailerAddict.get_trailer_embed_code
49
+ end
50
+ end
51
+
52
+ test "get_trailer_embed_code should return embed code" do
53
+ embed_code = TrailerAddict.get_trailer_embed_code("Iron Man")
54
+ assert embed_code.include?("<embed")
55
+ assert embed_code.include?("<object")
56
+ assert embed_code.include?("</object>")
57
+ assert embed_code.include?("</embed>")
58
+ end
59
+
60
+ test "get url returns a response object" do
61
+ test_response = TrailerAddict.get_url("http://example.com/")
62
+ assert_equal 200, test_response.code.to_i
63
+ end
64
+
65
+ test "getting nonexistent URL returns response object" do
66
+ test_response = TrailerAddict.get_url('http://thisisaurlthatdoesntexist.co.nz')
67
+ assert_equal 404, test_response.code.to_i
68
+ end
69
+
70
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-traileraddict
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Aaron Gough
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-26 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: hpricot
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: webmock
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: A simple API wrapper for TrailerAddict.com
50
+ email: aaron@aarongough.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - MIT-LICENSE
57
+ - README.rdoc
58
+ files:
59
+ - .gitignore
60
+ - MIT-LICENSE
61
+ - README.rdoc
62
+ - Rakefile
63
+ - VERSION
64
+ - lib/ruby-traileraddict.rb
65
+ - lib/ruby-traileraddict/traileraddict.rb
66
+ - test/fixtures/api_response.txt
67
+ - test/fixtures/example_com.txt
68
+ - test/fixtures/search.txt
69
+ - test/setup/test_unit_extensions.rb
70
+ - test/setup/url_mocks.rb
71
+ - test/test_helper.rb
72
+ - test/unit/trailer_addict_test.rb
73
+ has_rdoc: true
74
+ homepage: https://github.com/aarongough/ruby-traileraddict
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ - --line-numbers
81
+ - --inline-source
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project:
105
+ rubygems_version: 1.3.7
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: A simple API wrapper for TrailerAddict.com
109
+ test_files:
110
+ - test/setup/test_unit_extensions.rb
111
+ - test/setup/url_mocks.rb
112
+ - test/test_helper.rb
113
+ - test/unit/trailer_addict_test.rb