Skip to content

Ruby Book Task C

osherifo edited this page Apr 16, 2014 · 3 revisions

LAYOUTS

by creating a layout and naming it application.html.erb it will become the layout of all views with no layout associated with them `

<title>Pragprog Books Online Store</title> <%= stylesheet_link_tag "scaffold" %> <%= stylesheet_link_tag "depot", :media => "all" %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
<%= image_tag("logo.png") %> <%= @page_title || "Pragmatic Bookshelf" %>
<%= yield %>
`

the line <%= stylesheet_link_tag "depot", :media => "all" %> creates a link to the stylesheet found in yourepo/public/stylesheets/depo.css the line <%= yield %> is a place holder for the page to be opened the other lines just set up a layout.

FUNCTIONAL TESTING

rails provides a fast way to test for certain functionalities easily without having to do it manually.

after running $rake test you should find a file yourepo/test/functional/yourpage_controller_test.rb which should contain require 'test_helper' class StoreControllerTest < ActionController::TestCase test "should get index" do get :index #(1) assert_response :success #(2) end end (1) gets the index action from the specified controller and (2) checks that it returns a satisfactory result,you should define tests like the one created for each action you need.

other useful assertions: assert_select Element,Condition

Element and Condition can have many forms

Element: can be an html search where ids are preceded by # and css classes by # example: assert_select '#banner .flashy hello',3 asserts that there exists a hello between html tags with class .flashy which resides between html tags of id #banner 3 times.

Condition: a number: the specified element exists a specified number of times a string: the specified element contains a string with a specified value :minimum/maximum=>number: the specified element occurs at least/most a specified number of times regular expression: the specified element matches the regular expression find syntax for regular expressions below assert_equal(expected,value,msg) assert_not_equal(expected,value,msg)

regular expressions: enclosed in // operators: * zero or more + one or more [] or identifiers /d - integer

example /[/d]+[aeiou]*/ would look for 1 or more integers followed by 0 or more vowels 1232423 12321aeeoaeoi 1aaeieu

for a complete description check this

Clone this wiki locally