Module: Shoulda::Context::DSL::InstanceMethods
- Defined in:
- lib/shoulda/context/dsl.rb
Instance Method Summary collapse
-
#get_instance_of(object_or_klass) ⇒ Object
:nodoc:.
-
#instance_variable_name_for(klass) ⇒ Object
:nodoc:.
-
#subject ⇒ Object
Returns an instance of the class under test.
-
#subject_block ⇒ Object
:nodoc:.
Instance Method Details
#get_instance_of(object_or_klass) ⇒ Object
:nodoc:
255 256 257 258 259 260 261 |
# File 'lib/shoulda/context/dsl.rb', line 255 def get_instance_of(object_or_klass) # :nodoc: if object_or_klass.is_a?(Class) object_or_klass.new else object_or_klass end end |
#instance_variable_name_for(klass) ⇒ Object
:nodoc:
263 264 265 |
# File 'lib/shoulda/context/dsl.rb', line 263 def instance_variable_name_for(klass) # :nodoc: klass.to_s.split('::').last.underscore end |
#subject ⇒ Object
Returns an instance of the class under test.
class UserTest
should "be a user" do
assert_kind_of User, subject # passes
end
end
The subject can be explicitly set using the subject class method:
class UserTest
subject { User.first }
should "be an existing user" do
assert !subject.new_record? # uses the first user
end
end
The subject is used by all macros that require an instance of the class being tested.
247 248 249 |
# File 'lib/shoulda/context/dsl.rb', line 247 def subject @shoulda_subject ||= construct_subject end |
#subject_block ⇒ Object
:nodoc:
251 252 253 |
# File 'lib/shoulda/context/dsl.rb', line 251 def subject_block # :nodoc: (@shoulda_context && @shoulda_context.subject_block) || self.class.subject_block end |