Module: RSpec::WithArgs::ClassMethodExampleGroup

Extended by:
CommonClassMethods
Includes:
CommonInstanceMethods
Defined in:
lib/with_args.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CommonClassMethods

descriptee

Methods included from CommonInstanceMethods

#metadata, #subject_args

Class Method Details

.included(base) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/with_args.rb', line 78

def self.included(base)
  set_subject_proc(base.)
  set_subject_method_name(base.)

  base.subject do
    instance_eval &subject_proc
  end
end

.set_subject_method_name(metadata) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/with_args.rb', line 96

def self.set_subject_method_name()
  case d = [:example_group][:description_args].first
  when is_a?(Class)
    [:subject_method_name] = d
  when /^[.#]/
    [:subject_method_name] = d.gsub /^[.#]/, ""
  end
end

.set_subject_proc(metadata) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/with_args.rb', line 87

def self.set_subject_proc()
  [:subject_proc] = proc do |x|
    described_class.send(
      subject_method_name,
      *subject_args.map{|a| send(a)}
    )
  end
end

Instance Method Details

#subject_method_nameObject



109
110
111
# File 'lib/with_args.rb', line 109

def subject_method_name
  [:subject_method_name]
end

#subject_procObject



105
106
107
# File 'lib/with_args.rb', line 105

def subject_proc
  [:subject_proc]
end