Ruby On Rails in UA Icon_home Главная Add to bookmarks Translate translate Profile Войти
Регистрация Форум Блоги Пользователи Список джемов Rails проекты      Поиск   

Ruby On Rails in UA/Программирование на ROR/Использование Mocha

2008-06-09 17:53:58 Ответить  
admin
Ruslan Voloshin
Адрес: odessa
Сообщений: 1294
Регистр: 2007-03-13
его блог 40 сообщ.
Использование Mocha
  •  
Returns a mock object which will detect calls to any instance of this class.



mock(name) → mock object
mock(expected_methods = {}) → mock object
mock(name, expected_methods = {}) → mock object


Note that (contrary to expectations set up by stub) these expectations must be fulfilled during the test.



stub(name) → mock object
stub(stubbed_methods = {}) → mock object
stub(name, stubbed_methods = {}) → mock object

Note that (contrary to expectations set up by mock) these expectations need not be fulfilled during the test.



stub_everything(name) → mock object
stub_everything(stubbed_methods = {}) → mock object
stub_everything(name, stubbed_methods = {}) → mock object

Creates a mock object that accepts calls to any method. By default it will return nil for any method call. name and stubbed_methods work in the same way as for stub.



at_most(maximum_number_of_times) → expectation
Modifies expectation so that the expected method must be called at most a maximum_number_of_times.



at_most_once() → expectation

Modifies expectation so that the expected method must be called at most once.
multiple_yields(*parameter_groups) → expectation Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified parameter_groups. object = mock() object.expects(:expected_method).multiple_yields(['result_1', 'result_2'], ['result_3']) yielded_values = [] object.expected_method { |*values| yielded_values << values } yielded_values # => [['result_1', 'result_2'], ['result_3]]

May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then.


never() → expectation
Modifies expectation so that the expected method must never be called.


once() → expectation
Modifies expectation so that the expected method must be called exactly once. Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis.


raises(exception = RuntimeError?, message = nil) → expectation

Modifies expectation so that when the expected method is called, it raises the specified exception with the specified message.


May be called multiple times on the same expectation. Also see Expectation#then.

May be called in conjunction with Expectation#returns on the same expectation.


returns(value) → expectation
:call-seq: returns(*values) → expectation
Modifies expectation so that when the expected method is called, it returns the specified value.


If multiple values are given, these are returned in turn on consecutive calls to the method.

May be called multiple times on the same expectation. Also see Expectation#then.

May be called in conjunction with Expectation#raises on the same expectation.

If value is a Proc, then the expected method will return the result of calling Proc#call.

This usage is deprecated. Use explicit multiple return values and/or multiple expectations instead.

A Proc instance will be treated the same as any other value in a future release.


then() → expectation

Syntactic sugar to improve readability. Has no effect on state of the expectation.


times(range) → expectation
Modifies expectation so that the number of calls to the expected method must be within a specific range.

range can be specified as an exact integer or as a range of integers


with(*arguments, ¶meter_block) → expectation

Modifies expectation so that the expected method must be called with specified arguments.


May be used with parameter matchers in Mocha::ParameterMatchers?.

If a parameter_block is given, the block is called with the parameters passed to the expected method. The expectation is matched if the block evaluates to true.


yields(*parameters) → expectation

Modifies expectation so that when the expected method is called, it yields with the specified parameters.


May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then.

------------
Занимаюсь вебом и продвижением сайтов.
, , , , , , ,
Назадназад Новыйновый Ответитьответить
Ключевые слова:
Гости: 937 Онлайн: Dilshod Samatov, Виталий Худенко,
Rambler's Top100
О проекте по всем вопросам обращайтесь на support
Rubyclub.com.ua Copyright © 2007 - 2008