flickrmocks 0.8.14 → 0.8.15

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in hellop.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,75 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require File.expand_path(File.dirname(__FILE__) + '/lib/flickrmocks')
4
-
5
- # include all tasks
6
- Dir.glob("tasks/*.rb").each do |file|
7
- require File.expand_path(File.dirname(__FILE__) + "/#{file}")
8
- end
9
-
10
-
11
- begin
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- gem.name = "flickrmocks"
15
- gem.summary = %Q{Enables FlickRaw responses to be Marshaled.}
16
- gem.description = %Q{FlickrMocks makes it possible to Marshal responses
17
- generated from the FLickRaw gem. This is useful for
18
- Mocking/Stubbing the Flickr interface for testing purposes.
19
- The FlickRaw::Response and FlickRaw::ResponseList objects can
20
- not be Marshaled because they contain singleton's.}
21
- gem.email = "pouya@lavabit.com"
22
- gem.homepage = "http://github.com/takaltoo/flickrmocks"
23
- gem.authors = ["Takaltoo"]
24
-
25
- gem.add_development_dependency "rspec", ">=2.0.0.beta.22"
26
- gem.add_development_dependency "capybara"
27
- #gem.add_development_dependency 'ruby-debug19', :require => 'ruby-debug'
28
- gem.add_development_dependency 'factory_girl_rails', ">=1.0"
29
- gem.add_development_dependency 'faker','>=0.3.1'
30
-
31
- gem.add_dependency "flickraw", ">=0.8.2"
32
- gem.add_dependency 'chronic'
33
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
34
- end
35
- Jeweler::GemcutterTasks.new
36
- rescue LoadError
37
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
38
- end
39
-
40
- require 'rake/testtask'
41
- Rake::TestTask.new(:test) do |test|
42
- test.libs << 'lib' << 'test'
43
- test.pattern = 'test/**/test_*.rb'
44
- test.verbose = true
45
- end
46
-
47
- begin
48
- require 'rcov/rcovtask'
49
- Rcov::RcovTask.new do |test|
50
- test.libs << 'test'
51
- test.pattern = 'test/**/test_*.rb'
52
- test.verbose = true
53
- end
54
- rescue LoadError
55
- task :rcov do
56
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
57
- end
58
- end
59
-
60
- task :test => :check_dependencies
61
-
62
- task :default => :test
63
-
64
- require 'rake/rdoctask'
65
- Rake::RDocTask.new do |rdoc|
66
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
67
-
68
- rdoc.rdoc_dir = 'rdoc'
69
- rdoc.title = "flickrmocks #{version}"
70
- rdoc.rdoc_files.include('README*')
71
- rdoc.rdoc_files.include('lib/**/*.rb')
72
- end
73
-
74
-
75
-
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/flickrmocks.gemspec CHANGED
@@ -2,159 +2,34 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
+ $:.push File.expand_path("../lib", __FILE__)
6
+ require "flickr_mocks/version"
5
7
 
6
8
  Gem::Specification.new do |s|
7
- s.name = %q{flickrmocks}
8
- s.version = "0.8.14"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Takaltoo"]
12
- s.date = %q{2010-12-08}
13
- s.description = %q{FlickrMocks makes it possible to Marshal responses
14
- generated from the FLickRaw gem. This is useful for
9
+ s.name = "flickrmocks"
10
+ s.version = FlickrMocks::VERSION
11
+ s.platform = Gem::Platform::RUBY
12
+ s.authors = ["Takaltoo"]
13
+ s.email = ["pouya@lavabit.com"]
14
+ s.homepage = "http://rubygems.org/gems/flickrmocks"
15
+ s.summary = %q{Sample gem to see if can do a bundle based gem}
16
+ s.description = %q{FlickrMocks makes it possible to Marshal responses
17
+ generated from the FLickRaw gem. This is useful for
15
18
  Mocking/Stubbing the Flickr interface for testing purposes.
16
- The FlickRaw::Response and FlickRaw::ResponseList objects can
19
+ The FlickRaw::Response and FlickRaw::ResponseList objects can
17
20
  not be Marshaled because they contain singleton's.}
18
- s.email = %q{pouya@lavabit.com}
19
- s.extra_rdoc_files = [
20
- "README.rdoc"
21
- ]
22
- s.files = [
23
- ".autotest",
24
- ".document",
25
- ".gitignore",
26
- ".rspec",
27
- "MIT-LICENSE",
28
- "README.rdoc",
29
- "Rakefile",
30
- "VERSION",
31
- "autotest/discover.rb",
32
- "flickrmocks.gemspec",
33
- "lib/flickr_mocks/api/api.rb",
34
- "lib/flickr_mocks/api/flickr.rb",
35
- "lib/flickr_mocks/api/helpers.rb",
36
- "lib/flickr_mocks/api/options.rb",
37
- "lib/flickr_mocks/api/sanitize.rb",
38
- "lib/flickr_mocks/fixtures.rb",
39
- "lib/flickr_mocks/flickraw/custom_clone.rb",
40
- "lib/flickr_mocks/flickraw/custom_compare.rb",
41
- "lib/flickr_mocks/flickraw/custom_marshal.rb",
42
- "lib/flickr_mocks/flickraw/flickraw.rb",
43
- "lib/flickr_mocks/helpers.rb",
44
- "lib/flickr_mocks/models/commons_institution.rb",
45
- "lib/flickr_mocks/models/commons_institutions.rb",
46
- "lib/flickr_mocks/models/helpers.rb",
47
- "lib/flickr_mocks/models/photo.rb",
48
- "lib/flickr_mocks/models/photo_details.rb",
49
- "lib/flickr_mocks/models/photo_dimensions.rb",
50
- "lib/flickr_mocks/models/photo_search.rb",
51
- "lib/flickr_mocks/models/photo_size.rb",
52
- "lib/flickr_mocks/models/photo_sizes.rb",
53
- "lib/flickr_mocks/models/photos.rb",
54
- "lib/flickr_mocks/stubs.rb",
55
- "lib/flickr_mocks/version.rb",
56
- "lib/flickrmocks.rb",
57
- "spec/api/api_spec.rb",
58
- "spec/api/flickr_spec.rb",
59
- "spec/api/helper_spec.rb",
60
- "spec/api/options_spec.rb",
61
- "spec/api/sanitize_spec.rb",
62
- "spec/base/fixtures_spec.rb",
63
- "spec/base/flickraw/custom_clone_spec.rb",
64
- "spec/base/flickraw/custom_compare_spec.rb",
65
- "spec/base/flickraw/custom_marshal_spec.rb",
66
- "spec/base/helpers_spec.rb",
67
- "spec/base/stubs_spec.rb",
68
- "spec/base/version_spec.rb",
69
- "spec/fixtures/author_photos.marshal",
70
- "spec/fixtures/commons_institution_photos.marshal",
71
- "spec/fixtures/commons_institutions.marshal",
72
- "spec/fixtures/empty_photos.marshal",
73
- "spec/fixtures/expected_methods.marshal",
74
- "spec/fixtures/interesting_photos.marshal",
75
- "spec/fixtures/photo.marshal",
76
- "spec/fixtures/photo_details.marshal",
77
- "spec/fixtures/photo_size.marshal",
78
- "spec/fixtures/photo_sizes.marshal",
79
- "spec/fixtures/photos.marshal",
80
- "spec/models/commons_institution_spec.rb",
81
- "spec/models/commons_institutions_spec.rb",
82
- "spec/models/helpers_spec.rb",
83
- "spec/models/photo_details_spec.rb",
84
- "spec/models/photo_dimensions_spec.rb",
85
- "spec/models/photo_search_spec.rb",
86
- "spec/models/photo_size_spec.rb",
87
- "spec/models/photo_sizes_spec.rb",
88
- "spec/models/photo_spec.rb",
89
- "spec/models/photos_spec.rb",
90
- "spec/shared_examples/array_accessor.rb",
91
- "spec/shared_examples/collection.rb",
92
- "spec/shared_examples/image_url_helpers.rb",
93
- "spec/shared_examples/size_accessor.rb",
94
- "spec/spec_helper.rb",
95
- "tasks/fixtures.rb"
96
- ]
97
- s.homepage = %q{http://github.com/takaltoo/flickrmocks}
21
+ s.extra_rdoc_files = ["README.rdoc"]
98
22
  s.rdoc_options = ["--charset=UTF-8"]
23
+ s.rubyforge_project = "flickrmocks"
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
99
27
  s.require_paths = ["lib"]
100
- s.rubygems_version = %q{1.3.7}
101
- s.summary = %q{Enables FlickRaw responses to be Marshaled.}
102
- s.test_files = [
103
- "spec/shared_examples/array_accessor.rb",
104
- "spec/shared_examples/size_accessor.rb",
105
- "spec/shared_examples/collection.rb",
106
- "spec/shared_examples/image_url_helpers.rb",
107
- "spec/models/helpers_spec.rb",
108
- "spec/models/photo_details_spec.rb",
109
- "spec/models/photo_size_spec.rb",
110
- "spec/models/commons_institution_spec.rb",
111
- "spec/models/photo_sizes_spec.rb",
112
- "spec/models/commons_institutions_spec.rb",
113
- "spec/models/photos_spec.rb",
114
- "spec/models/photo_dimensions_spec.rb",
115
- "spec/models/photo_spec.rb",
116
- "spec/models/photo_search_spec.rb",
117
- "spec/api/api_spec.rb",
118
- "spec/api/flickr_spec.rb",
119
- "spec/api/options_spec.rb",
120
- "spec/api/sanitize_spec.rb",
121
- "spec/api/helper_spec.rb",
122
- "spec/base/stubs_spec.rb",
123
- "spec/base/helpers_spec.rb",
124
- "spec/base/version_spec.rb",
125
- "spec/base/flickraw/custom_clone_spec.rb",
126
- "spec/base/flickraw/custom_compare_spec.rb",
127
- "spec/base/flickraw/custom_marshal_spec.rb",
128
- "spec/base/fixtures_spec.rb",
129
- "spec/spec_helper.rb"
130
- ]
131
-
132
- if s.respond_to? :specification_version then
133
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
134
- s.specification_version = 3
135
-
136
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
137
- s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
138
- s.add_development_dependency(%q<capybara>, [">= 0"])
139
- s.add_development_dependency(%q<factory_girl_rails>, [">= 1.0"])
140
- s.add_development_dependency(%q<faker>, [">= 0.3.1"])
141
- s.add_runtime_dependency(%q<flickraw>, [">= 0.8.2"])
142
- s.add_runtime_dependency(%q<chronic>, [">= 0"])
143
- else
144
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
145
- s.add_dependency(%q<capybara>, [">= 0"])
146
- s.add_dependency(%q<factory_girl_rails>, [">= 1.0"])
147
- s.add_dependency(%q<faker>, [">= 0.3.1"])
148
- s.add_dependency(%q<flickraw>, [">= 0.8.2"])
149
- s.add_dependency(%q<chronic>, [">= 0"])
150
- end
151
- else
152
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
153
- s.add_dependency(%q<capybara>, [">= 0"])
154
- s.add_dependency(%q<factory_girl_rails>, [">= 1.0"])
155
- s.add_dependency(%q<faker>, [">= 0.3.1"])
156
- s.add_dependency(%q<flickraw>, [">= 0.8.2"])
157
- s.add_dependency(%q<chronic>, [">= 0"])
158
- end
28
+ s.add_runtime_dependency(%q<flickraw>, [">= 0.8.2"])
29
+ s.add_runtime_dependency(%q<chronic>, [">= 0"])
30
+ s.add_development_dependency(%q<rspec>, [">= 2.2.0"])
31
+ s.add_development_dependency(%q<capybara>, [">= 0"])
32
+ s.add_development_dependency(%q<factory_girl_rails>, [">= 1.0"])
33
+ s.add_development_dependency(%q<faker>, [">= 0.3.1"])
159
34
  end
160
35
 
@@ -15,30 +15,36 @@ module FlickrMocks
15
15
  end
16
16
 
17
17
  def self.photos(params)
18
+ raise ArgumentError.new("Expecting a Hash argument.") unless params.is_a?(Hash)
18
19
  photos = Api.flickr_photos(params)
19
20
  PhotoSearch.new photos,Api.search_params(params)
20
21
  end
21
22
 
22
23
  def self.photo_details(params)
24
+ raise ArgumentError.new("Expecting a Hash argument.") unless params.is_a?(Hash)
23
25
  photo = Api.flickr_photo(params)
24
26
  sizes = Api.flickr_photo_sizes(params)
25
27
  @this = @photo = PhotoDetails.new(photo,sizes)
26
28
  end
27
29
 
28
30
  def self.photo(params)
31
+ raise ArgumentError.new("Expecting a Hash argument") unless params.is_a?(Hash)
29
32
  Photo.new Api.flickr_photo(params)
30
33
  end
31
34
 
32
35
  def self.photo_sizes(params)
36
+ raise ArgumentError.new("Expecting a Hash argument") unless params.is_a?(Hash)
33
37
  PhotoSizes.new Api.flickr_photo_sizes(params)
34
38
  end
35
39
 
36
40
  def self.interesting_photos(params)
41
+ raise ArgumentError.new("Expecting a Hash argument") unless params.is_a?(Hash)
37
42
  photos = Api.flickr_interestingness(params)
38
43
  PhotoSearch.new photos,Api.interesting_params(params)
39
44
  end
40
45
 
41
46
  def self.commons_institutions(params)
47
+ raise ArgumentError.new("Expecting a Hash argument") unless params.is_a?(Hash)
42
48
  institutions = Api.flickr_commons_institutions
43
49
  CommonsInstitutions.new institutions,Api.commons_institutions_params(params)
44
50
  end
@@ -1,103 +1,146 @@
1
1
  module FlickrMocks
2
2
  module Stubs
3
+ module Api
4
+ def self.all
5
+ [:photos,:photo_details,:photo,:photo_sizes,
6
+ :interesting_photos,:commons_institutions].each do |method|
7
+ self.send(method)
8
+ end
9
+ end
10
+
11
+ def self.photos
12
+ lambda {::FlickrMocks::Api.stub(:photos) do |params|
13
+ ::FlickrMocks::Stubs::Flickr.search
14
+ case params
15
+ when Hash then
16
+ PhotoSearch.new flickr.photos.search(::FlickrMocks::Api.search_options(params)),::FlickrMocks::Api.search_params(params)
17
+ else
18
+ raise ArgumentError
19
+ end
20
+ end}.call
21
+ end
3
22
 
4
- def self.stub_flickr
5
- [:stub_search,:stub_getInfo,:stub_getSizes,:stub_interestingness,:stub_commons_institutions].each do |method|
6
- self.send(method)
23
+ def self.photo_details
24
+ lambda {::FlickrMocks::Api.stub(:photo_details) do |params|
25
+ ::FlickrMocks::Stubs::Flickr.getInfo
26
+ ::FlickrMocks::Stubs::Flickr.getSizes
27
+ case params
28
+ when Hash then
29
+ PhotoDetails.new(flickr.photos.getInfo(::FlickrMocks::Api.photo_options(params)),
30
+ flickr.photos.getSizes(::FlickrMocks::Api.photo_options(params)))
31
+ else
32
+ raise ArgumentError
33
+ end
34
+ end}.call
7
35
  end
36
+
8
37
  end
9
38
 
10
39
 
11
- def self.stub_search
12
- fixtures = Fixtures.instance
13
- Proc.new { flickr.photos.stub(:search) do |params|
14
- if !params.is_a?(Hash)
15
- raise FlickRaw::FailedResponse.new('Parameterless searches have been disabled. Please use flickr.photos.getRecent instead.',
16
- 'code','flickr.photos.search'
17
- )
18
- elsif(params[:tags] == 'garbage' || params[:user_id] == 'garbage')
19
- fixtures.empty_photos
20
- elsif(params[:tags] && params[:user_id])
21
- fixtures.author_photos
22
- elsif params.has_key?(:tags)
23
- fixtures.photos
24
- elsif params.has_key?(:user_id)
25
- fixtures.author_photos
26
- else
27
- raise FlickRaw::FailedResponse.new('Parameterless searches have been disabled. Please use flickr.photos.getRecent instead.',
28
- 'code','flickr.photos.search'
29
- )
30
- end
40
+ module Flickr
41
+ def self.all
42
+ [:search,:getInfo,:getSizes,:interestingness,:commons_institutions].each do |method|
43
+ self.send(method)
31
44
  end
32
- }.call
33
- end
45
+ end
46
+
34
47
 
35
- def self.stub_getInfo
36
- Proc.new {
37
- flickr.photos.stub(:getInfo) do |params|
38
- if !params.is_a?(Hash)
39
- raise FlickRaw::FailedResponse.new('Photo not found',
40
- 'code', 'flickr.photos.getInfo')
41
- elsif !params.has_key?(:photo_id)
42
- raise FlickRaw::FailedResponse.new('Photo not found',
43
- 'code', 'flickr.photos.getInfo')
44
- elsif params[:photo_id] == 'garbage'
45
- raise FlickRaw::FailedResponse.new('Photo "%s" not found (invalid ID)' % params[:photo_id],
46
- 'code','flickr.photos.getInfo')
47
- else
48
- Fixtures.instance.photo_details
48
+ def self.search
49
+ fixtures = Fixtures.instance
50
+ lambda { flickr.photos.stub(:search) do |params|
51
+ if !params.is_a?(Hash)
52
+ raise FlickRaw::FailedResponse.new('Parameterless searches have been disabled. Please use flickr.photos.getRecent instead.',
53
+ 'code','flickr.photos.search'
54
+ )
55
+ elsif(params[:tags] == 'garbage' || params[:user_id] == 'garbage')
56
+ fixtures.empty_photos
57
+ elsif(params[:tags] && params[:user_id])
58
+ fixtures.author_photos
59
+ elsif params.has_key?(:tags)
60
+ fixtures.photos
61
+ elsif params.has_key?(:user_id)
62
+ fixtures.author_photos
63
+ else
64
+ raise FlickRaw::FailedResponse.new('Parameterless searches have been disabled. Please use flickr.photos.getRecent instead.',
65
+ 'code','flickr.photos.search'
66
+ )
67
+ end
49
68
  end
50
- end
51
- }.call
52
- end
69
+ }.call
70
+ end
53
71
 
54
- def self.stub_getSizes
55
- Proc.new {
56
- flickr.photos.stub(:getSizes) do |params|
57
- if !params.is_a?(Hash)
58
- raise FlickRaw::FailedResponse.new('Photo not found',
59
- 'code', 'flickr.photos.getSizes')
60
- elsif !params.has_key?(:photo_id)
61
- raise FlickRaw::FailedResponse.new('Photo not found',
62
- 'code', 'flickr.photos.getSizes')
63
- elsif params[:photo_id] == 'garbage'
64
- raise FlickRaw::FailedResponse.new('Photo not found',
65
- 'code','flickr.photos.getSizes')
66
- else
67
- Fixtures.instance.photo_sizes
72
+ def self.getInfo
73
+ lambda {
74
+ flickr.photos.stub(:getInfo) do |params|
75
+ if !params.is_a?(Hash)
76
+ raise FlickRaw::FailedResponse.new('Photo not found',
77
+ 'code', 'flickr.photos.getInfo')
78
+ elsif !params.has_key?(:photo_id)
79
+ raise FlickRaw::FailedResponse.new('Photo not found',
80
+ 'code', 'flickr.photos.getInfo')
81
+ elsif params[:photo_id] == 'garbage'
82
+ raise FlickRaw::FailedResponse.new('Photo "%s" not found (invalid ID)' % params[:photo_id],
83
+ 'code','flickr.photos.getInfo')
84
+ elsif params[:photo_id] == nil
85
+ raise FlickRaw::FailedResponse.new('Photo "nil" not found (invalid ID)',
86
+ 'code','flickr.photos.getInfo')
87
+ else
88
+ Fixtures.instance.photo_details
89
+ end
68
90
  end
69
- end
70
- }.call
71
- end
91
+ }.call
92
+ end
72
93
 
73
- def self.stub_interestingness
74
- Proc.new {
75
- flickr.interestingness.stub(:getList) do |params|
76
- if !params.is_a?(Hash)
77
- Fixtures.instance.interesting_photos
78
- elsif !params.has_key?(:date)
79
- Fixtures.instance.interesting_photos
80
- elsif params[:date] == 'garbage'
81
- raise FlickRaw::FailedResponse.new('Not a valid date string',
82
- 'code','flickr.interestingness.getList'
83
- )
84
- elsif params[:date] == '2000-01-01'
85
- Fixtures.instance.empty_photos
86
- else
87
- Fixtures.instance.interesting_photos
94
+ def self.getSizes
95
+ lambda {
96
+ flickr.photos.stub(:getSizes) do |params|
97
+ if !params.is_a?(Hash)
98
+ raise FlickRaw::FailedResponse.new('Photo not found',
99
+ 'code', 'flickr.photos.getSizes')
100
+ elsif !params.has_key?(:photo_id)
101
+ raise FlickRaw::FailedResponse.new('Photo not found',
102
+ 'code', 'flickr.photos.getSizes')
103
+ elsif params[:photo_id] == 'garbage'
104
+ raise FlickRaw::FailedResponse.new('Photo not found',
105
+ 'code','flickr.photos.getSizes')
106
+ elsif params[:photo_id] == nil
107
+ raise FlickRaw::FailedResponse.new('Photo not found',
108
+ 'code','flickr.photos.getSizes')
109
+ else
110
+ Fixtures.instance.photo_sizes
111
+ end
88
112
  end
89
- end
90
- }.call
91
- end
113
+ }.call
114
+ end
115
+
116
+ def self.interestingness
117
+ lambda {
118
+ flickr.interestingness.stub(:getList) do |params|
119
+ if !params.is_a?(Hash)
120
+ Fixtures.instance.interesting_photos
121
+ elsif !params.has_key?(:date)
122
+ Fixtures.instance.interesting_photos
123
+ elsif params[:date] == 'garbage'
124
+ raise FlickRaw::FailedResponse.new('Not a valid date string',
125
+ 'code','flickr.interestingness.getList'
126
+ )
127
+ elsif params[:date] == '2000-01-01'
128
+ Fixtures.instance.empty_photos
129
+ else
130
+ Fixtures.instance.interesting_photos
131
+ end
132
+ end
133
+ }.call
134
+ end
92
135
 
93
- def self.stub_commons_institutions
94
- Proc.new {
95
- flickr.commons.stub(:getInstitutions) do
136
+ def self.commons_institutions
137
+ lambda {
138
+ flickr.commons.stub(:getInstitutions) do
96
139
  Fixtures.instance.commons_institutions
97
- end
98
- }.call
140
+ end
141
+ }.call
142
+ end
99
143
  end
100
-
101
144
  end
102
145
  end
103
146