Có thêm một điều chúng ta cần phải kiểm tra. Hãy chắc chắn rằng hồ sơ của người dùng được cập nhật khi họ nhấp vào liên kết trong lời mời của chúng tôi. Điều đó sẽ gây ra một vấn đề. Chúng tôi không muốn cập nhật hồ sơ cá nhân của người dùng, nhưng chúng tôi muốn chắc chắn rằng một nỗ lực được thực hiện. | Controller Tests 78 Let s use the facebook_post method to make sure our invitation s create method works def test_valid_create facebook_post create ids 1234 assert_response success assert_template create end Excellent. That test passes and feels much more like a typical Rails controller test. There s just one more thing we need to test. Let s make sure a user s profile is updated when they click the link in our invite. That s going to cause a problem. We don t want to actually update a user s profile but we want to make sure an attempt is made. We ll need a new technique to test that. Using Mocks and Stubs We ve successfully modified our tests to generate the correct Facebook signature to let us test our controllers without Facebook. We got stuck trying to verify that a profile update was happening. We need to verify that our profile is being updated but we don t want our tests to actually talk to Facebook. Not only will that make them run slowly it also makes them less reliable. We could do something ugly such as wrap the code that talks to Facebook inside an if RAILS_ENV test statement. That doesn t give us much confidence that our code does what we want. Instead we can use mocks and stubs. If you haven t heard of mocks and stubs you aren t alone. Mock objects are a relative newcomer onto the testing scene. In fact the first paper that described them wasn t even written until the year Mocks and stubs are objects that can be used to replace functionality after the fact. For instance in our new action test we could use a stub object to replace the Facebook user. our user stub accepts the same calls as the real user but eliminates the side effects. This will allow us to test the hometown method without needing to talk to several Ruby libraries make it easy to use mock and stub objects in our code. We re going to use FlexMock from Jim Weirich in our examples. Before we go any further you ll need to install the FlexMock gem 1. Mocks were first .