|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | describe IMGKit::Source do |
4 | | - |
| 4 | + |
5 | 5 | describe "#url?" do |
6 | 6 | it "should return true if passed a url like string" do |
7 | 7 | source = IMGKit::Source.new('http://google.com') |
8 | 8 | source.should be_url |
9 | 9 | end |
10 | | - |
| 10 | + |
11 | 11 | it "should return false if passed a file" do |
12 | 12 | source = IMGKit::Source.new(File.new(__FILE__)) |
13 | 13 | source.should_not be_url |
14 | 14 | end |
15 | | - |
| 15 | + |
16 | 16 | it "should return false if passed HTML" do |
17 | 17 | source = IMGKit::Source.new('<blink>Oh Hai!</blink>') |
18 | 18 | source.should_not be_url |
|
22 | 22 | source = IMGKit::Source.new("<blink>Oh Hai!</blink>\nhttp://google.com") |
23 | 23 | source.should_not be_url |
24 | 24 | end |
| 25 | + |
| 26 | + it "should return false if passed string starts with http but is not a url" do |
| 27 | + source = IMGKit::Source.new('http') |
| 28 | + source.should_not be_url |
| 29 | + end |
25 | 30 | end |
26 | | - |
| 31 | + |
27 | 32 | describe "#file?" do |
28 | 33 | it "should return true if passed a file" do |
29 | 34 | source = IMGKit::Source.new(File.new(__FILE__)) |
|
34 | 39 | source = IMGKit::Source.new(Tempfile.new 'temp_file') |
35 | 40 | source.should be_file |
36 | 41 | end |
37 | | - |
| 42 | + |
38 | 43 | it "should return false if passed a url like string" do |
39 | 44 | source = IMGKit::Source.new('http://google.com') |
40 | 45 | source.should_not be_file |
41 | 46 | end |
42 | | - |
| 47 | + |
43 | 48 | it "should return false if passed HTML" do |
44 | 49 | source = IMGKit::Source.new('<blink>Oh Hai!</blink>') |
45 | 50 | source.should_not be_file |
46 | 51 | end |
47 | 52 | end |
48 | | - |
| 53 | + |
49 | 54 | describe "#html?" do |
50 | 55 | it "should return true if passed HTML" do |
51 | 56 | source = IMGKit::Source.new('<blink>Oh Hai!</blink>') |
52 | 57 | source.should be_html |
53 | 58 | end |
54 | | - |
| 59 | + |
55 | 60 | it "should return false if passed a file" do |
56 | 61 | source = IMGKit::Source.new(File.new(__FILE__)) |
57 | 62 | source.should_not be_html |
58 | 63 | end |
59 | | - |
| 64 | + |
60 | 65 | it "should return false if passed a url like string" do |
61 | 66 | source = IMGKit::Source.new('http://google.com') |
62 | 67 | source.should_not be_html |
63 | 68 | end |
64 | 69 | end |
65 | | - |
| 70 | + |
66 | 71 | describe "#to_s" do |
67 | 72 | it "should return the HTML if passed HTML" do |
68 | 73 | source = IMGKit::Source.new('<blink>Oh Hai!</blink>') |
69 | 74 | source.to_s.should == '<blink>Oh Hai!</blink>' |
70 | 75 | end |
71 | | - |
| 76 | + |
72 | 77 | it "should return a path if passed a file" do |
73 | 78 | source = IMGKit::Source.new(File.new(__FILE__)) |
74 | 79 | source.to_s.should == __FILE__ |
75 | 80 | end |
76 | | - |
| 81 | + |
77 | 82 | it "should return the url if passed a url like string" do |
78 | 83 | source = IMGKit::Source.new('http://google.com') |
79 | 84 | source.to_s.should == 'http://google.com' |
80 | 85 | end |
81 | 86 | end |
82 | | - |
| 87 | + |
83 | 88 | end |
0 commit comments