TAILIEUCHUNG - Rails for Java Developers phần 8

Cú pháp dạng thủ tục (procedural syntax) vẫn còn được hỗ trợ, có vẻ như là ngoài tầm vực của mọi đối tượng, nhưng thực sự là thuộc một thể hiện của class Object tên là 'main'. Vì class này là cha của mọi class khác, nó trở trên ẩn đối với mọi lớp và đối tượng. | Testing Interactions with Mock Objects 227 Like Java Ruby does not ship with a mock object library. We will use You can install FlexMock via RubyGems gem install flexmock To make FlexMock available to all tests in a Rails application require it in Download code rails_xt test require flexmock Now for a test. The Rails XT sample application does not have a manager layer so we will introduce a new feature in the controller layer. Instead of simply accessing all quips users should be allowed to filter quips based on their preferences. our application will store user preferences in the session and use a third-party API to filter content. The third-party API will be implemented through a @filter_service instance on the controller. It is possible to call the FlexMock API via freestanding classes. It is much simpler however to just begin our test case by including Flex-Mock TestCase Download code rails_xt test functional include FlexMock TestCase Adding FlexMock TestCase gives us helper methods for creating mocks and it automatically validates the mocks during teardown. The QuipsController should provide a new method list_with_user_filter. This method should return all quips minus any that are rejected by the FilterService. Here is the test Download code rails_xt test functional def test_list_with_user_filter filter flexmock filter do m Array nil .returns quips quip_1 end @ @filter_service filter get list_with_user_filter assert_equal quips quip_1 assigns quips assert_response success assert_template list_with_user_filter end 9. http software flexmock Testing Interactions with Mock Objects 228 On line 2 the flexmock method creates a mock object. The argument is a name that will be used in error messages. In the Java version the mock had to have a specific interface so jMock could know what methods the mock

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.