Class: FakeWeb::Fixture

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_web/fixture.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, method, uri, response) ⇒ Fixture

Returns a new instance of Fixture.



12
13
14
15
16
17
# File 'lib/fake_web/fixture.rb', line 12

def initialize(path, method, uri, response)
  @path = path
  @method = method
  @uri = uri
  @response = response
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/fake_web/fixture.rb', line 3

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/fake_web/fixture.rb', line 3

def path
  @path
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/fake_web/fixture.rb', line 3

def response
  @response
end

#uriObject (readonly)

Returns the value of attribute uri.



3
4
5
# File 'lib/fake_web/fixture.rb', line 3

def uri
  @uri
end

Class Method Details

.register(path) ⇒ Object



5
6
7
8
9
10
# File 'lib/fake_web/fixture.rb', line 5

def self.register(path)
  Dir.glob("#{path}/*.fixture") do |name|
    fixture = YAML.load_file name
    fixture.register
  end
end

Instance Method Details

#file_nameObject



19
20
21
# File 'lib/fake_web/fixture.rb', line 19

def file_name
  @file_name ||= generate_file_name
end

#registerObject



23
24
25
# File 'lib/fake_web/fixture.rb', line 23

def register
  FakeWeb.register_uri(method, uri, :response => response)
end

#saveObject



27
28
29
30
31
32
33
# File 'lib/fake_web/fixture.rb', line 27

def save
  Dir.chdir path do
    File.open(file_name, 'w') do |f|
      f.write self.to_yaml
    end
  end
end