Module: Gravatar::TestCase
- Defined in:
- lib/gravatar/test_case.rb
Class Attribute Summary collapse
-
.fixtures_path ⇒ Object
Returns the value of attribute fixtures_path.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_current_mock! ⇒ Object
- #clear_account(g = grav) ⇒ Object
-
#grav(*args) ⇒ Object
Set or get the Gravatar instance to test against.
-
#mock_response(name = :__unassigned) ⇒ Object
Sets the filename of the mock response to be used for the next request.
Class Attribute Details
.fixtures_path ⇒ Object
Returns the value of attribute fixtures_path.
5 6 7 |
# File 'lib/gravatar/test_case.rb', line 5 def fixtures_path @fixtures_path end |
Class Method Details
.included(base) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gravatar/test_case.rb', line 27 def self.included(base) base.instance_eval do # Sets or gets the default email address to create Gravs with # default: "[email protected]" def default_email(new_one = nil) !new_one ? @default_email ||= "[email protected]" : @default_email = new_one end def fixtures_path @fixtures_path || Gravatar::TestCase.fixtures_path end def fixtures_path=(a) @fixtures_path = a end end end |
Instance Method Details
#apply_current_mock! ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gravatar/test_case.rb', line 71 def apply_current_mock! if mock_response FakeWeb.allow_net_connect = false FakeWeb.register_uri :post, grav.url, :response => mock_response else # don't set to true, instead leave it set to whatever # the user has it set to. This way if the user manually # sets it to false, they don't have a 4-hour-long WTF. # FakeWeb.allow_net_connect = false end end |
#clear_account(g = grav) ⇒ Object
100 101 102 103 104 |
# File 'lib/gravatar/test_case.rb', line 100 def clear_account(g = grav) g.user_images.each do |usrimg_hash, (, url)| g.delete_user_image!(usrimg_hash) end end |
#grav(*args) ⇒ Object
Set or get the Gravatar instance to test against.
Examples:
grav # return the default grav with bogus email
grav(email) # replace with a new grav with given email
grav # return the current grav with above email
90 91 92 93 94 95 96 97 98 |
# File 'lib/gravatar/test_case.rb', line 90 def grav(*args) if args.empty? @grav ||= Gravatar.new(self.class.default_email, :rescue_errors => false) else = args. .reverse_merge! :rescue_errors => false @grav = Gravatar.new(*args + []) end end |
#mock_response(name = :__unassigned) ⇒ Object
Sets the filename of the mock response to be used for the next request. Set to nil to disable mock responses entirely.
If name is omitted, the contents of the current mock response, if any, are returned.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gravatar/test_case.rb', line 50 def mock_response(name = :__unassigned) if name == :__unassigned @mock_response else if name.nil? FakeWeb::Registry.instance.uri_map.each do |uri, methods| if uri.to_s == grav.url methods.delete :post end end @mock_response = nil else if fixtures_path.nil? raise "fixtures_path is not set! Try setting that first." end @mock_response = File.read(File.join(fixtures_path, name)) end end end |