undertexter 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  require "rspec"
2
2
  require "webmock/rspec"
3
3
  require "undertexter"
4
+ require "vcr"
4
5
  require "subtitle"
5
6
  require "undertexter/error"
6
7
 
@@ -8,4 +9,14 @@ WebMock.allow_net_connect!
8
9
 
9
10
  RSpec.configure do |config|
10
11
  config.mock_with :rspec
12
+ config.extend VCR::RSpec::Macros
13
+ end
14
+
15
+ VCR.config do |c|
16
+ c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
17
+ c.stub_with :webmock
18
+ c.default_cassette_options = {
19
+ record: :new_episodes
20
+ }
21
+ c.allow_http_connections_when_no_cassette = false
11
22
  end
@@ -7,13 +7,15 @@ describe Subtitle do
7
7
  @new_file = "/tmp/#{@title.gsub(/\s+/, '.')}.zip"
8
8
 
9
9
  @subtitle = Subtitle.new({
10
- :details => "http://www.undertexter.se/?p=undertext&id=23984",
10
+ :details => "http://www.undertexter.se/23984/",
11
11
  :downloads => 100,
12
12
  :cds => 1,
13
13
  :title => @title,
14
14
  :movie_title => "127 Hours (127 Timmar)",
15
15
  :language => :swedish
16
16
  })
17
+
18
+ WebMock.allow_net_connect!
17
19
  end
18
20
 
19
21
  it "should be an instance of subtitle" do
@@ -21,7 +23,7 @@ describe Subtitle do
21
23
  end
22
24
 
23
25
  it "should have the right accessors" do
24
- @subtitle.details.should eq("http://www.undertexter.se/?p=undertext&id=23984")
26
+ @subtitle.details.should eq("http://www.undertexter.se/23984/")
25
27
  @subtitle.downloads.should eq(100)
26
28
  @subtitle.cds.should eq(1)
27
29
  @subtitle.title.should eq("127 Hours 2010 DVDSCR XViD-MC8")
@@ -34,7 +36,7 @@ describe Subtitle do
34
36
  end
35
37
 
36
38
  it "should have created an existing file" do
37
- FileUtils.rm(@new_file)
39
+ FileUtils.rm(@new_file) if File.exists?(@new_file)
38
40
  @subtitle.download!
39
41
  File.exists?(@new_file).should be_true
40
42
  end
@@ -44,14 +46,4 @@ describe Subtitle do
44
46
  @subtitle.download!(:to => '/tmp/new_dir')
45
47
  %x{ls /tmp/new_dir}.should_not be_empty
46
48
  end
47
-
48
- it "should be able to download the file to a specific relative directory" do
49
- folder = "#{Dir.pwd}/spec/data"
50
-
51
- @subtitle.download!(:to => 'spec/data')
52
-
53
- %x{ls #{folder}}.should_not be_empty
54
-
55
- %x{cd #{folder} && rm 127.Hours.2010.DVDSCR.XViD-MC8.zip}
56
- end
57
49
  end
@@ -1,12 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Undertexter do
4
- before(:all) do
4
+ use_vcr_cassette "tt0499549"
5
+
6
+ before(:each) do
5
7
  @use = Undertexter.find("tt0499549")
6
8
  end
7
9
 
8
10
  it "should return return at least 31 subtitles" do
9
- Undertexter.should have_at_least(31).find("tt0499549")
11
+ Undertexter.find("tt0499549").count.should >= 31
10
12
  end
11
13
 
12
14
  it "should contain cds that is of the type Fixnum" do
@@ -25,6 +27,10 @@ describe Undertexter do
25
27
  @use.reject {|subtitle| subtitle.downloads <= 0}.count.should_not be(0)
26
28
  end
27
29
 
30
+ it "should not be empty" do
31
+ @use.should_not be_empty
32
+ end
33
+
28
34
  it "should contain titles that does not have whitespace in the end of beginning" do
29
35
  @use.each {|subtitle| subtitle.title.should_not match(/^\s+.+\s+$/)}
30
36
  end
@@ -33,29 +39,29 @@ describe Undertexter do
33
39
  @use.each {|subtitle| subtitle.title.should_not be_empty}
34
40
  end
35
41
 
36
- it "should contain the right detailss" do
37
- @use.each {|subtitle| subtitle.details.should match(/^http:\/\/www\.undertexter\.se\/\?p=undertext&id=\d+$/)}
42
+ it "should contain the right details" do
43
+ @use.each {|subtitle| subtitle.details.should match(/^http:\/\/www\.undertexter\.se\/\d+\/$/)}
38
44
  end
39
45
  end
40
46
 
41
47
 
42
48
  describe Undertexter, "trying to find a non existing movie" do
49
+ use_vcr_cassette "non-existing"
50
+
43
51
  it "should not return any subtitles" do
44
52
  Undertexter.find("some random name").count.should be(0)
45
53
  end
46
54
  end
47
55
 
48
56
  describe Undertexter, "trying to search for a movie using a title" do
49
- before(:all) do
50
- @use = Undertexter.find("die hard")
51
- end
57
+ use_vcr_cassette "die-hard"
52
58
 
53
- it "should return some subtitles" do
54
- Undertexter.should have_at_least(36).find("avatar")
59
+ before(:each) do
60
+ @use = Undertexter.find("die hard")
55
61
  end
56
62
 
57
63
  it "should return some subtitles when searching for a movie with whitespace" do
58
- Undertexter.should have_at_least(41).find("die hard")
64
+ @use.count.should >= 41
59
65
  end
60
66
 
61
67
  it "should have 6 die hard movies that does not contain any title" do
@@ -63,7 +69,7 @@ describe Undertexter, "trying to search for a movie using a title" do
63
69
  end
64
70
 
65
71
  it "should contain the right details, again" do
66
- @use.each {|subtitle| subtitle.details.should match(/^http:\/\/www\.undertexter\.se\/\?p=undertext&id=\d+$/i)}
72
+ @use.each {|subtitle| subtitle.details.should match(/^http:\/\/www\.undertexter\.se\/\d+\/$/)}
67
73
  end
68
74
 
69
75
  it "should have a movie title" do
@@ -80,7 +86,8 @@ describe Undertexter, "trying to search for a movie using a title" do
80
86
 
81
87
  it "should return the same id for every link" do
82
88
  @use.each_with_index do |subtitle, index|
83
- subtitle.url.match(/id=(\d+)/)[1].should eq(@use[index].details.match(/id=(\d+)/)[1])
89
+ subtitle.url.match(/id=(\d+)$/)[1].should
90
+ eq(@use[index].details.match(/^http:\/\/www\.undertexter\.se\/(\d+)\/$/)[1])
84
91
  end
85
92
  end
86
93
 
@@ -97,21 +104,32 @@ describe Undertexter, "trying to search for a movie using a title" do
97
104
  end
98
105
  end
99
106
 
100
- describe Undertexter, "should work when trying to fetch some english subtitles" do
101
- it "should return at least 48 subtitles" do
102
- Undertexter.should have_at_least(48).find("tt0840361", :language => :english)
103
- end
104
-
105
- it "should return at least 8 subtitles" do
106
- Undertexter.should have_at_least(8).find("tt0840361", :language => :swedish)
107
+ describe "deactivated" do
108
+ it "should raise an error if trying to fetch an english subtitle" do
109
+ lambda {
110
+ Undertexter.find("tt0840361", :language => :english)
111
+ }.should raise_error(ArgumentError, "Support for english subtitles are deactivated - for now.")
107
112
  end
113
+ end
114
+
115
+ describe Undertexter, "should work when trying to fetch some english subtitles" do
116
+ use_vcr_cassette "tt0840361"
117
+
118
+ # Deactivated - for now - 2011-05-11
119
+ #
120
+ # it "should return at least 48 subtitles" do
121
+ # Undertexter.should have_at_least(48).find("tt0840361", :language => :english)
122
+ # end
123
+ # it "should return the right url when trying to fetch an english sub" do
124
+ # Undertexter.find("tt0840361", :language => :english).first.url.should match(/http:\/\/eng\.undertexter\.se\/subtitle\.php\?id=\d+/i)
125
+ # end
108
126
 
109
127
  it "should return at least 8 subtitles" do
110
128
  Undertexter.should have_at_least(8).find("tt0840361", :language => :strange)
111
129
  end
112
130
 
113
- it "should return the right url when trying to fetch an english sub" do
114
- Undertexter.find("tt0840361", :language => :english).first.url.should match(/http:\/\/eng\.undertexter\.se\/subtitle\.php\?id=\d+/i)
131
+ it "should return at least 8 subtitles" do
132
+ Undertexter.should have_at_least(8).find("tt0840361", :language => :swedish)
115
133
  end
116
134
 
117
135
  it "should return the right url when trying to fetch an swedish sub" do
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "undertexter"
6
- s.version = "0.1.8"
6
+ s.version = "0.1.9"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Linus Oleander"]
9
9
  s.email = ["linus@oleander.nu"]
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
25
25
 
26
26
  s.add_development_dependency("rspec", "2.4.0")
27
27
  s.add_development_dependency("webmock")
28
+ s.add_development_dependency("vcr")
28
29
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: undertexter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.8
5
+ version: 0.1.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Linus Oleander
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-03 00:00:00 +02:00
13
+ date: 2011-05-11 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -79,6 +79,17 @@ dependencies:
79
79
  version: "0"
80
80
  type: :development
81
81
  version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: vcr
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id007
82
93
  description: A basic API for Undertexter.se.
83
94
  email:
84
95
  - linus@oleander.nu
@@ -100,8 +111,11 @@ files:
100
111
  - lib/undertexter/array.rb
101
112
  - lib/undertexter/error.rb
102
113
  - spec/array_spec.rb
103
- - spec/data/127.Hours.2010.DVDSCR.XViD-MC8
104
114
  - spec/fixtures/error.html
115
+ - spec/fixtures/vcr_cassettes/die-hard.yml
116
+ - spec/fixtures/vcr_cassettes/non-existing.yml
117
+ - spec/fixtures/vcr_cassettes/tt0499549.yml
118
+ - spec/fixtures/vcr_cassettes/tt0840361.yml
105
119
  - spec/spec_helper.rb
106
120
  - spec/subtitle_spec.rb
107
121
  - spec/undertexter_spec.rb
@@ -136,8 +150,11 @@ specification_version: 3
136
150
  summary: A basic API for Undertexter.se
137
151
  test_files:
138
152
  - spec/array_spec.rb
139
- - spec/data/127.Hours.2010.DVDSCR.XViD-MC8
140
153
  - spec/fixtures/error.html
154
+ - spec/fixtures/vcr_cassettes/die-hard.yml
155
+ - spec/fixtures/vcr_cassettes/non-existing.yml
156
+ - spec/fixtures/vcr_cassettes/tt0499549.yml
157
+ - spec/fixtures/vcr_cassettes/tt0840361.yml
141
158
  - spec/spec_helper.rb
142
159
  - spec/subtitle_spec.rb
143
160
  - spec/undertexter_spec.rb
File without changes