0%

In this article, we will study Include and Extend and see the differences between those two. Include is for adding methods to an instance of a class and extend is for adding methods to any type of object(Class or an instance of Class). Let’s take a look at a small example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Foo
def bar
puts 'foobar'
end
end

class IncludeModule
include Foo
end

class ExtendModule
extend Foo
end

class Plain; end
Read more »

这里有一个 form 表单,表单里包含多个 input fields,使用 jQuery 可以简单的实现 keyboard navigation。 这意味着,如果用户光标定位在1st input field,然后按下『向下键』(down key),光标应该跳转到下一个 input field。

为了实现这个功能,这个我们需要定义两个 Helper 方法,功能分别是找到下一个和上一个给定的 element

Read more »

1. Command Line Tools

1
$ xcode-select --install

2. Homebrew

1
2
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
$ brew doctor

3. RVM

1
$ \curl -sSL https://get.rvm.io | bash

4. Ruby 1.9.3

1
2
3
$ brew install gcc46 # ruby 1.9.3 required
$ rvm install 1.9.3
$ rvm use 1.9.3 --default # ruby 1.9.3 as default

5. MySQL

1
2
3
$ brew install mysql
$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Middleman - makes developing websites simple

Middleman is a static site generator using all the shortcuts and tools in modern web development. Getting started

Installation

1
$ gem install middleman

After installed successfully, it will add one new command to your environment, with 3 useful features:

  1. middleman init - starting a new site
  2. middleman server - start a local web server running at: http://localhost:4567/
  3. middleman build - exporting the static site to build folder

Wufoo - the online form builder

Wufoo is an Internet application that helps anybody build amazing online forms. With Wufoo, you can skip all the hard stuff (because it does it all for you), and start getting things done.

Read more »

So far we’ve spent a lot of time going over controller and model testing, and use fabrication to generate test data. Now it’s time to put everything together for ingegration testing-in other words, makding sure thoes models and controllers all play nicely with other models and controllers in the application. These tests are called feature specs in RSpec.

A feature spec covers more ground, and represents how actual users will interact with your code. We write feature specs with Cypybara, an extremely useful Ruby library to help define steps of a feature spec and simulate real-world use of your application.

Add additional gems

add cypybara and launchy in the Gemfile

1
2
3
4
5
group :test do
gem "faker", "~> 1.1.2"
gem "capybara", "~> 2.1.0"
gem "launchy", "~> 2.2.0"
end

and run $ bundle install

A basic feature spec

Capybara lets you simulate how a user would interact with your application throgh a web browser, using a series of easy-to-understand methods like click_link, fill_in, and visit. These methods let you to descirbe a test scenario for your app.

add a new file app/spec/features/user_sign_in_spec.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
require 'spec_helper'

feature "User sign in" do
scenario "with registered user" do
user = Fabricate(:user)
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
expect(page).to have_content "Sign in successfully."
expect(page).to have_content user.full_name
end
end
Read more »