{"action":"closed","issue":{"url":"https://api.github.com/repos/pumpkincouture/lumberyard/issues/4","labels_url":"https://api.github.com/repos/pumpkincouture/lumberyard/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/pumpkincouture/lumberyard/issues/4/comments","events_url":"https://api.github.com/repos/pumpkincouture/lumberyard/issues/4/events","html_url":"https://github.com/pumpkincouture/lumberyard/issues/4","id":56323531,"number":4,"title":"Sinatra unit tests","user":{"login":"mjansen401","id":626088,"avatar_url":"https://avatars.githubusercontent.com/u/626088?v=3","gravatar_id":"","url":"https://api.github.com/users/mjansen401","html_url":"https://github.com/mjansen401","followers_url":"https://api.github.com/users/mjansen401/followers","following_url":"https://api.github.com/users/mjansen401/following{/other_user}","gists_url":"https://api.github.com/users/mjansen401/gists{/gist_id}","starred_url":"https://api.github.com/users/mjansen401/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjansen401/subscriptions","organizations_url":"https://api.github.com/users/mjansen401/orgs","repos_url":"https://api.github.com/users/mjansen401/repos","events_url":"https://api.github.com/users/mjansen401/events{/privacy}","received_events_url":"https://api.github.com/users/mjansen401/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-03T02:06:42Z","updated_at":"2015-02-04T22:13:42Z","closed_at":"2015-02-04T22:13:42Z","body":"Some notes on testing the sinatra routes (in lib/lumberyard.rb):\r\n\r\n### Asserting on last_response\r\n\r\n```ruby\r\nit \"displays the title of the app\" do\r\n  get '/'\r\n  expect(last_response.body).to include(\"LumberYard\")\r\nend\r\n```\r\n\r\nI don't like asserting on the body of the response. For this, you are expecting the page to render correctly. I prefer to use the status code of the response itself. For example:\r\n\r\n```ruby\r\nexpect(last_response.status).to eq(200)\r\n```\r\n\r\nThese HTTP response status codes are good to get familiar with: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success\r\n\r\n### Expected test data/random order for tests\r\n\r\nTests like these:\r\n\r\n```\r\nit \"redirects to error page if user is not found\" do                                            \r\n  post '/username', {\"username_name\" => 'radams'}                                 \r\n  expect(last_request.path).to eq('/username')                                    \r\n  expect(last_response.body).to include(\"That username is invalid. Please input your username.\")\r\nend                    \r\n\r\nit \"display admin page if employee is type admin\" do     \r\n  post '/username', {\"username_name\" => 'dlockhart'}     \r\n  expect(last_response.body).to include(\"Welcome, Diane\")\r\n  expect(last_response.body).to include(\"Add client\")    \r\nend                                                                                                                 \r\n```\r\n\r\nExpect that the database has been seeded a certain way, e.g. that radams is NOT in the database and dlockhart is. Your tests should always be able to run independent of any other test, and not relying on previously existing data. Each test should set up and tear down the data it needs. It seems like these tests depend on the employee_spec.rb file executing first.\r\n\r\nTo verify this works, add `config.order = :rand` to your spec_helper.rb for the RSpec config. No matter the test order, your tests should pass.\r\n\r\n### Readability of Tests\r\n\r\nThe context `admin employee chooses an action` is not exactly clear about what is being asserted in the tests. I can't tell at a glance if these are error messages or what is happening for these responses. Part of this is because you are asserting on the body of the response. I would rather you assert that a certain template is rendered, which could match up nicely with what the `get_correct_form` method does for you.\r\n\r\n"}}