Last active
October 1, 2015 07:33
-
-
Save kalarani/9249c6033084d981d32e to your computer and use it in GitHub Desktop.
Types of tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StringUtil < ActiveRecord::Base | |
def reverse | |
self.reversed_string = self.given_string.reverse | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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