Module: RailsExtension::ActiveSupportExtension::TestCase::InstanceMethods
- Defined in:
- lib/rails_extension/active_support_extension/test_case.rb
Instance Method Summary collapse
-
#assert_changes(expression, message = nil, &block) ⇒ Object
basically a copy of assert_difference, but without any explicit comparison as it is simply stating that something will change (designed for updated_at).
-
#deny_changes(expression, message = nil, &block) ⇒ Object
Just a negation of assert_changes.
- #method_missing_with_create_object(symb, *args, &block) ⇒ Object
- #model_name ⇒ Object
Instance Method Details
#assert_changes(expression, message = nil, &block) ⇒ Object
basically a copy of assert_difference, but without any explicit comparison as it is simply stating that something will change (designed for updated_at)
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 182 def assert_changes(expression, = nil, &block) b = block.send(:binding) exps = Array.wrap(expression) before = exps.map { |e| eval(e, b) } yield exps.each_with_index do |e, i| error = "#{e.inspect} didn't change" error = "#{}.\n#{error}" if assert_not_equal(before[i], eval(e, b), error) end end |
#deny_changes(expression, message = nil, &block) ⇒ Object
Just a negation of assert_changes
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 195 def deny_changes(expression, = nil, &block) b = block.send(:binding) exps = Array.wrap(expression) before = exps.map { |e| eval(e, b) } yield exps.each_with_index do |e, i| error = "#{e.inspect} changed" error = "#{}.\n#{error}" if assert_equal(before[i], eval(e, b), error) end end |
#method_missing_with_create_object(symb, *args, &block) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 142 def method_missing_with_create_object(symb,*args, &block) method = symb.to_s # if method =~ /^create_(.+)(\!?)$/ if method =~ /^create_([^!]+)(!?)$/ factory = if( $1 == 'object' ) # doesn't work for controllers yet. Need to consider # singular and plural as well as "tests" method. # Probably should just use the explicit factory # name in the controller tests. # self.class.name.sub(/Test$/,'').underscore model_name.underscore else $1 end bang = $2 = args. if bang.blank? record = Factory.build(factory,) # record.attributes = options # occassionally needed (study_subject_id) record.save record else Factory(factory,) end else # super(symb,*args, &block) method_missing_without_create_object(symb,*args, &block) end end |
#model_name ⇒ Object
136 137 138 139 140 |
# File 'lib/rails_extension/active_support_extension/test_case.rb', line 136 def model_name # self.class.name.sub(/Test$/,'') # self.class.name.demodulize.sub(/Test$/,'') self.class.st_model_name end |