Module: RSpec::RubyContentMatchers

Defined in:
lib/generator_spec/matchers/content/have_call.rb,
lib/generator_spec/main.rb,
lib/generator_spec/matchers/content/have_block.rb,
lib/generator_spec/matchers/content/have_calls.rb,
lib/generator_spec/matchers/content/have_class.rb,
lib/generator_spec/matchers/content/have_method.rb,
lib/generator_spec/matchers/content/have_module.rb,
lib/generator_spec/matchers/content/have_region.rb,
lib/generator_spec/matchers/content/inherit_from.rb,
lib/generator_spec/matchers/migration/have_index.rb,
lib/generator_spec/matchers/migration/have_table.rb,
lib/generator_spec/matchers/content/have_subclass.rb,
lib/generator_spec/matchers/migration/have_column.rb,
lib/generator_spec/matchers/content/include_module.rb,
lib/generator_spec/matchers/migration/have_up_down.rb,
lib/generator_spec/matchers/migration/have_tbl_column.rb

Overview

This method tries to see if a specific method is contained in the generated file. It can operate (should) on either a file name or the raw content

generated_file_name.should have_method "hello" # 'my/path/say_hello.rb'.should have_method "hello"

say_hello_file_content.should have_method "hello"

Defined Under Namespace

Classes: HaveBlock, HaveCall, HaveCalls, HaveClass, HaveMethod, HaveModule, HaveRegion, HaveSubclass, IncludeModule, InheritFrom

Instance Method Summary collapse

Instance Method Details

#be_active_recordObject



36
37
38
# File 'lib/generator_spec/matchers/content/inherit_from.rb', line 36

def be_active_record    
  InheritFrom.new('ActiveRecord::Base')    
end

#be_dm_resourceObject



36
37
38
# File 'lib/generator_spec/matchers/content/include_module.rb', line 36

def be_dm_resource
  IncludeModule.new 'DataMapper::Resource'
end

#be_document(type, options = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generator_spec/matchers/content/include_module.rb', line 40

def be_document(type, options=nil)
  doc_type = options == :embedded ? 'EmbeddedDocument' : 'Document'
  doc_orm = case type 
  when :mongo_mapper
    'MongoMapper'
  when :mongoid
    'Mongoid'
  else
    raise ArgumentError, "Unknown document type #{type.inspect}"
  end    
  IncludeModule.new "#{doc_orm}::#{doc_type}"
end

#have_add_column(name, type = 'string') ⇒ Object



6
7
8
# File 'lib/generator_spec/matchers/migration/have_column.rb', line 6

def have_add_column(name, type='string')
  HaveCall.new("t.#{type}", ":#{name}")
end

#have_add_tbl_column(tbl_name, col_name, type = 'string') ⇒ Object



10
11
12
# File 'lib/generator_spec/matchers/migration/have_tbl_column.rb', line 10

def have_add_tbl_column(tbl_name, col_name, type = 'string')
  HaveCall.new('add_column', ":#{tbl_name}\s*,\s*:#{col_name}\s*,\s*:#{type}")
end

#have_add_tbl_index(tbl_name, index_name) ⇒ Object



2
3
4
# File 'lib/generator_spec/matchers/migration/have_index.rb', line 2

def have_add_tbl_index(tbl_name, index_name)
  HaveCall.new('add_index', ":#{tbl_name}\s*,\s*:#{index_name}")
end

#have_block(name, options = {}) ⇒ Object



47
48
49
# File 'lib/generator_spec/matchers/content/have_block.rb', line 47

def have_block(name, options={})
  HaveBlock.new(name, options)
end

#have_call(method, args = nil) ⇒ Object



42
43
44
# File 'lib/generator_spec/matchers/content/have_call.rb', line 42

def have_call(method, args = nil)
  HaveCall.new(method, args)
end

#have_calls(calls) ⇒ Object



39
40
41
# File 'lib/generator_spec/matchers/content/have_calls.rb', line 39

def have_calls(calls)
  HaveCalls.new(calls)
end

#have_change_column(name, type = 'string') ⇒ Object



16
17
18
# File 'lib/generator_spec/matchers/migration/have_column.rb', line 16

def have_change_column(name, type='string')
  HaveCall.new("t.change", ":#{name}\s*,\s*:#{type}")
end

#have_change_table(name) ⇒ Object



6
7
8
# File 'lib/generator_spec/matchers/migration/have_table.rb', line 6

def have_change_table(name)
  HaveBlock.new('change_table', :args => ":#{name}")
end

#have_change_tbl_column(tbl_name, col_name, type = 'string') ⇒ Object



14
15
16
# File 'lib/generator_spec/matchers/migration/have_tbl_column.rb', line 14

def have_change_tbl_column tbl_name, col_name, type='string'
  HaveCall.new('change_column', ":#{tbl_name}\s*,\s*:#{col_name}\s*,\s*:#{type}")
end

#have_class(klass, type = nil) ⇒ Object Also known as: be_class



36
37
38
# File 'lib/generator_spec/matchers/content/have_class.rb', line 36

def have_class(klass, type = nil)
  HaveClass.new(klass, type)
end

#have_class_self(name, options = {}) ⇒ Object



51
52
53
# File 'lib/generator_spec/matchers/content/have_block.rb', line 51

def have_class_self(name, options={})
  HaveBlock.new('class', :args => '<< self')
end

#have_columnObject



9
10
11
# File 'lib/generator_spec/matchers/migration/have_column.rb', line 9

def have_add_column(name, type='string')
  HaveCall.new("t.#{type}", ":#{name}")
end

#have_columns(columns = {}) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/generator_spec/matchers/migration/have_column.rb', line 11

def have_columns(columns = {})
  raise ArgumentError, "Columns must be passed as a :name => :type Hash" if !columns.kind_of? Hash
  HaveCalls.new columns
end

#have_controller_class(klass) ⇒ Object Also known as: be_controller_class



47
48
49
# File 'lib/generator_spec/matchers/content/have_class.rb', line 47

def have_controller_class(klass)
  HaveClass.new(klass, :controller)
end

#have_create_table(name) ⇒ Object



2
3
4
# File 'lib/generator_spec/matchers/migration/have_table.rb', line 2

def have_create_table(name)
  HaveBlock.new('create_table', :args => ":#{name}")
end

#have_down(&block) ⇒ Object



6
7
8
# File 'lib/generator_spec/matchers/migration/have_up_down.rb', line 6

def have_down &block
  HaveMethod.new 'down', :class, &block
end

#have_drop_table(name) ⇒ Object



10
11
12
# File 'lib/generator_spec/matchers/migration/have_table.rb', line 10

def have_drop_table(name)
  HaveCall.new('drop_table', ":#{name}")
end

#have_helper_class(klass) ⇒ Object Also known as: be_helper_class



41
42
43
# File 'lib/generator_spec/matchers/content/have_class.rb', line 41

def have_helper_class(klass)
  HaveClass.new(klass, :helper)
end

#have_method(method, type = nil) ⇒ Object



56
57
58
# File 'lib/generator_spec/matchers/content/have_method.rb', line 56

def have_method(method, type = nil)
  HaveMethod.new(method, type)
end

#have_migration(klass) ⇒ Object Also known as: be_migration



52
53
54
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 52

def have_migration(klass)
  HaveSubclass.new(klass, 'ActiveRecord::Migration')
end

#have_module(module_name) ⇒ Object Also known as: be_module



32
33
34
# File 'lib/generator_spec/matchers/content/have_module.rb', line 32

def have_module(module_name)
  HaveModule.new(module_name)
end

#have_observer_class(klass) ⇒ Object Also known as: be_observer, be_observer_class



45
46
47
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 45

def have_observer_class(klass)
  HaveSubclass.new(klass, 'ActiveRecord::Observer', :observer)
end

#have_privateObject



44
45
46
# File 'lib/generator_spec/matchers/content/have_region.rb', line 44

def have_private
  HaveRegion.new :private
end

#have_protectedObject



40
41
42
# File 'lib/generator_spec/matchers/content/have_region.rb', line 40

def have_protected
  HaveRegion.new :protected
end

#have_publicObject



36
37
38
# File 'lib/generator_spec/matchers/content/have_region.rb', line 36

def have_public
  HaveRegion.new :public
end

#have_remove_column(name) ⇒ Object



2
3
4
# File 'lib/generator_spec/matchers/migration/have_column.rb', line 2

def have_remove_column(name)
  HaveCall.new('t.remove', ":#{name}")
end

#have_remove_index(name) ⇒ Object



6
7
8
# File 'lib/generator_spec/matchers/migration/have_index.rb', line 6

def have_remove_index(name)
  HaveCall.new('remove_index', ":#{tbl_name}\s*,\s*:#{index_name}")
end

#have_remove_tbl_column(tbl_name, col_name) ⇒ Object



2
3
4
# File 'lib/generator_spec/matchers/migration/have_tbl_column.rb', line 2

def have_remove_tbl_column(tbl_name, col_name)
  HaveCall.new('remove_column', ":#{tbl_name}\s*,\s*:#{col_name}")
end

#have_rename_table(name) ⇒ Object



14
15
16
# File 'lib/generator_spec/matchers/migration/have_table.rb', line 14

def have_rename_table(name)
  HaveCall.new('rename_table', ":#{name}")
end

#have_rename_tbl_column(tbl_name, new_name) ⇒ Object



6
7
8
# File 'lib/generator_spec/matchers/migration/have_tbl_column.rb', line 6

def have_rename_tbl_column(tbl_name, new_name)
  HaveCall.new('rename_column', ":#{tbl_name}\s*,\s*:#{new_name}")
end

#have_subclass(klass, superclass, type = nil) ⇒ Object Also known as: be_subclass



40
41
42
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 40

def have_subclass(klass, superclass, type=nil)
  HaveSubclass.new(klass, superclass, type)
end

#have_timestampsObject



20
21
22
# File 'lib/generator_spec/matchers/migration/have_column.rb', line 20

def have_timestamps
  HaveCall.new("t.timestamps")
end

#have_up(&block) ⇒ Object



2
3
4
# File 'lib/generator_spec/matchers/migration/have_up_down.rb', line 2

def have_up &block
  HaveMethod.new 'up', :class, &block
end

#include_module(module_name) ⇒ Object



32
33
34
# File 'lib/generator_spec/matchers/content/include_module.rb', line 32

def include_module(module_name)
  IncludeModule.new(module_name)
end

#inherit_from(klass) ⇒ Object Also known as: be_subclass_of



31
32
33
# File 'lib/generator_spec/matchers/content/inherit_from.rb', line 31

def inherit_from(klass)
  InheritFrom.new(klass)
end