user_steps.rb 1.51 KB
When(/^I click the (.+) link$/) do |text|
  click_link text
end

When(/^I press the (.+) button$/) do |text|
  click_button text
end

When(/^I fill the (.+) field with "(.+)"$/) do |field, text|
  fill_in field, :with => text
end

Then(/^the field "(.*?)" should be filled with "(.*?)"$/) do |field, value|
  expect(page.find_field(field).value).to eq(value)
end

Then(/^my name should have changed to (.+)$/) do |text|
  @user.reload
  expect(@user.name).to eq(text)
end

Then(/^I should be in the User Projects page$/) do
  expect(page).to have_content("#{@user.name} Projects")
end

When(/^I take a picture of the page$/) do
  page.save_screenshot("/tmp/picture.png")
end

When(/^I click the "(.*?)" icon$/) do |icon|
  find('#' + icon).click # the hashtag symbol is necessary to find the id of a HTML element
  sleep(1) #This sleep is essential to make the popup visible when we take a picture of the page
end

Given(/^I am logged in as a Colab user$/) do
  colab_user = FactoryGirl.build(:colab_user)

  set_header('Remote-User', colab_user.uid)
  set_header('Remote-User-Data', {
    'nickname': colab_user.uid,
    'name': colab_user.name,
    'email': colab_user.email
  }.to_json)
end

Then(/^I should be at the Home page$/) do
  expect(page).to have_content("Understanding Code Metrics") # This ensures that capybara waits all the redirects to get finished before trying to check the URL
  expect(current_path).to eq(root_path(locale: I18n.locale))
end

Then(/^I should be logged in$/) do
  expect(page).to have_no_link("Sign In")
end