Class: Test::Spec::Rails::Macros::Response::TestGenerator

Inherits:
Proxy
  • Object
show all
Defined in:
lib/test/spec/rails/macros/response.rb

Instance Attribute Summary collapse

Attributes inherited from Proxy

#test_case

Instance Method Summary collapse

Constructor Details

#initialize(test_case, status, message) ⇒ TestGenerator

Returns a new instance of TestGenerator.


16
17
18
19
20
21
# File 'lib/test/spec/rails/macros/response.rb', line 16

def initialize(test_case, status, message)
  self.status = status
  self.message = message

  super(test_case)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(verb, action, params = {}) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/test/spec/rails/macros/response.rb', line 23

def method_missing(verb, action, params={})
  if [:get, :post, :put, :delete, :options].include?(verb.to_sym)
    description = "should not find resource with #{verb.to_s.upcase} on `#{action}'"
    description << " #{params.inspect}" unless params.blank?

    status = self.status
    message = self.message
    
    if defined?(:ActiveRecord)
      test_case.it description do
        begin
          send(verb, action, immediate_values(params))
          status.should.messaging(message) == status
        rescue ActiveRecord::RecordNotFound
          :not_found.should.messaging(message) == status
        end
      end
    else
      test_case.it description do
        send(verb, action, immediate_values(params))
        status.should.messaging(message) == status
      end
    end
  else
    super
  end
end

Instance Attribute Details

#expectedObject

Returns the value of attribute expected


14
15
16
# File 'lib/test/spec/rails/macros/response.rb', line 14

def expected
  @expected
end

#messageObject

Returns the value of attribute message


14
15
16
# File 'lib/test/spec/rails/macros/response.rb', line 14

def message
  @message
end

#statusObject

Returns the value of attribute status


14
15
16
# File 'lib/test/spec/rails/macros/response.rb', line 14

def status
  @status
end