Module: Test::Spec::Rails::Macros::ClassMethods

Defined in:
lib/test/spec/rails/macros.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object

Filter calls to fixture methods so we can use them in the definitions



41
42
43
44
45
46
47
48
# File 'lib/test/spec/rails/macros.rb', line 41

def method_missing(method, *arguments, &block)
  if known_fixture?(method)
    arguments = arguments.map { |a| a.inspect }
    Test::Spec::Rails::Macros::LazyValue.new("#{method}(#{arguments.join(', ')})")
  else
    super
  end
end

Instance Method Details

#known_fixture?(name) ⇒ Boolean

Returns true when the passed name is a known table, we assume known tables also have fixtures

Returns:

  • (Boolean)


36
37
38
# File 'lib/test/spec/rails/macros.rb', line 36

def known_fixture?(name)
  respond_to?(:fixture_table_names) && fixture_table_names.include?(name.to_s)
end

#shouldObject

Returns an instance of the Should class, this allows you to call macros from the test case is a nice way:

should.disallow.get :index


31
32
33
# File 'lib/test/spec/rails/macros.rb', line 31

def should
  Test::Spec::Rails::Macros::Should.new(self)
end