Cucumber features for creating a keychain model - moralesalberto/personal GitHub Wiki

Create Feature

Feature: Create a keychain record

  Background: A user logs into the application
    Given a user is not logged in
    And is a valid user with email "[email protected]" and password "working123"
    When the user goes to the root page of the application
    Then the user should be redirected to the login page
    When the user enters his correct credentials in the login page, email: "[email protected]" and password "working123"    
    And submits the login page
    Then the user should be shown the root page

  Scenario: A user creates a keychain record
    When the user goes to the new keychain page
    And fills in the keychain name: "name of the key"
    And username: "theusername"
    And password: "thepassword"
    And description: "This is a key that I use all the time"
    And submits the new keychain form
    Then a new keychain record is created with the name "name of the key", and password: "thepassword"
    And the list of keychains should be shown, with names "name of the key"

Step Definitions

When(/^the user goes to the new keychain page$/) do
  visit(new_keychain_path)
end

When(/^fills in the keychain name: "(.*?)"$/) do |keychain_name|
  fill_in('keychain_name', :with => keychain_name)
end

When(/^username: "(.*?)"$/) do |username|
  fill_in('keychain_username', :with => username)
end

When(/^password: "(.*?)"$/) do |password|
  fill_in('keychain_password', :with => password)
end

When(/^description: "(.*?)"$/) do |description|
  fill_in('keychain_description', :with => description)
end

When(/^submits the new keychain form$/) do
  click_on('Save keychain')
end

Then(/^a new keychain record is created with the name "(.*?)", and password: "(.*?)"$/) do |name, password|
  keychains = Keychain.where('name = ?', name)
  keychains.size.should eq(1)
  keychains.first.password_encrypted.should_not eq(password)
  keychains.first.password.should eq(password)
end

Then(/^the admin is emailed that the keychain "(.*?)" was shown to a user$/) do |name|
  emails = ActionMailer::Base.deliveries.select {|email| email.subject =~ /#{name}/}
  emails.size.should eq(1)
  emails.first.to.first.should eq('[email protected]')
end