Skip to content

Instantly share code, notes, and snippets.

@kalarani
Last active October 1, 2015 07:33
Show Gist options
  • Save kalarani/9249c6033084d981d32e to your computer and use it in GitHub Desktop.
Save kalarani/9249c6033084d981d32e to your computer and use it in GitHub Desktop.
Types of tests
require ‘selenium-webdriver’
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://string_util_test.com"
input_element = driver.find_element(:name, 'given_string')
input_element.send_keys "Functional Test"
reverse_button = driver.find_element(:id, "reverse")
reverse_button.click
assert driver.find_element(:id, "reversed_string").text.eq?("tseT lanoitcnuF")
driver.quit
class StringUtil < ActiveRecord::Base
def reverse
self.reversed_string = self.given_string.reverse
end
end
class AddStringUtilModel < ActiveRecord::Migration
def change
create_table :string_utils, id: false do |t|
t.primary_key :given_string, :string
t.string :reversed_string, null: false
end
end
end
require 'rails_helper'
describe StringUtil do
it 'should persist reversed string in db' do
new_string = StringUtil.new(:given_string => "Integration test")
new_string.reverse
expect(new_string.reversed_string).to eq("tset noitargetnI")
new_string.save!
saved_string = StringUtil.where(:given_string => "Integration test").first
expect(saved_string.reversed_string).to eq("tset noitargetnI")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment