PageRenderTime 133ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/features/step_definitions/room_steps.rb

https://bitbucket.org/anhhoang/studify
Ruby | 75 lines | 57 code | 6 blank | 12 comment | 1 complexity | 3c4e4b510c67567dc910afec7c03fc99 MD5 | raw file
  1. # "(.*?)" should be in the user list
  2. # the status of "(.*?)" should be "(.*?)"
  3. # "(.*?)" chooses the choice "([A-Z])"
  4. # "(.*?)" chooses the choice "([A-Z])"
  5. # "(.*?)" should see the correct explanation
  6. # room "(.*?)" should be in the room list
  7. # the room mode of "(.*?)" should be "(.*?)"
  8. # I create a room with title "(.*?)" and room mode "(.*?)"
  9. # I expand room "(.*?)"
  10. # "(.*?)" should be in the user list with status "(.*?)"
  11. #
  12. #
  13. Given /^"(.*?)" should be in the user list$/ do |name|
  14. user_list = page.find("#user_list")
  15. assert user_list.has_content?(name)
  16. end
  17. And /^the status of "(.*?)" should be "(.*?)"$/ do |name,status|
  18. user_id = User.find_by_name(name).id
  19. assert page.find("#user-#{user_id}").has_content?(status)
  20. end
  21. Then /^"(.*?)" chooses the choice "([A-Z])"$/ do |name,choice_letter|
  22. user = User.find_by_name(name)
  23. choice = user.room.question.choices.where(choice_letter: choice_letter).first
  24. click_button("choice-#{choice.id.to_s}")
  25. end
  26. Then /^"(.*?)" should see the correct explanation$/ do |name|
  27. user = User.find_by_name(name)
  28. question = user.room.question
  29. if user.histories.last.question_id!=question.id
  30. assert page.has_content?("You didn't select an answer. See explanation below.")
  31. elsif user.histories.last.choice.correct
  32. assert page.has_content?("Congratulations! You got the right answer.")
  33. else
  34. assert page.has_content?("Sorry you got the wrong answer. See explanation below.")
  35. end
  36. end
  37. Then /^room "(.*?)" should be in the room list$/ do |title|
  38. assert page.find("#room_list").has_content?(title)
  39. end
  40. And /^the room mode of "(.*?)" should be "(.*?)"$/ do |title,room_mode|
  41. room = Room.find_by_title(title)
  42. assert page.find("#room_#{room.id}").has_content?(room_mode)
  43. end
  44. Given /^I create a room with title "(.*?)" and room mode "(.*?)"$/ do |title,room_mode|
  45. step %Q[I wait 1 seconds]
  46. step %Q[I press "New room"]
  47. step %Q[I wait 1 seconds]
  48. step %Q[I fill in "Room title" with "#{title}"]
  49. step %Q[I select "#{room_mode}" from "Room mode"]
  50. step %Q[I press "Create Room"]
  51. step %Q[I wait 1 seconds]
  52. end
  53. Given /^I expand room "(.*?)"$/ do |title|
  54. room = Room.find_by_title(title)
  55. step %Q[I click on "#room_#{room.id}"]
  56. end
  57. And /^"(.*?)" should be in the user list with status "(.*?)"$/ do |name,status|
  58. step %Q["#{name}" should be in the user list]
  59. step %Q[the status of "#{name}" should be "#{status}"]
  60. end
  61. And /^what$/ do
  62. puts page.body
  63. end