saimonmoore/mock_server — comment on commit c63e46a2c7d434fb4e7f64ebf48dcf5d4384f1c0
File:  line 0
By saimonmoore:

No the idea is that matcher procs contain rspec expectations. These throw exceptions on failure which we catch, store and reraise just after the request has been issued. This was you can assert properly in matcher procs and the spec will pick up the failure correctly e.g.:

feature "Renaming task lists" do

before :each do
mock_bootstrap

mock_server_add_record('task_lists', 'task_lists_edit_title')
mock_server_enable_routes('**/tasks.json', '**/task_lists/*')

mock_server_get '/api/2/projects/1/tasks.json' do |request, recorded_request|
request.query.should == recorded_request.query
request.query.should == 'count=0'
end
end

after :each do
mock_server_reset!
end

scenario "Should be able to rename a task list" do

mock_server_put '/api/2/projects/1/task_lists/1' do |request, recorded_request|
request.body.name.should == recorded_request.body.name
request.body.name.should == 'foo bar'
end

within("#project_earthworks_task_lists") do
click_link 'Tasks'
end

within("#task_list_1") do
find('a.task_list_rename').click

within("form.task_list_form") do
fill_in 'task_list_name', :with => 'foo bar'
click_button('Update Task List')
end
end

mock_server_reraise_matcher_exceptions
mock_server_success_stack.any? {|path| path == '/api/2/projects/1/task_lists/1'}.should be_true

within("#task_list_1") do
find('.task_list_name', :visible => true).should have_content('foo bar')
end

end #scenario

Returning simple boolean conditionals doesn't make much sense because the only thing it tells you is that the was some error during the request but not what error. This is why using expectations is preferred.