Commit 40e5ad02 by Truong Ba Dieu

Turnip

parent 2e82af5d
......@@ -67,8 +67,6 @@ gem 'capistrano-rails', '~> 1.1.1'
gem 'capistrano-rvm', github: "capistrano/rvm"
group :development, :test do
# gem 'capybara' # Integration test tool to simulate a user on a website.
# gem 'capybara_minitest_spec' # MiniTest::Spec expectations for Capybara node matchers.
gem 'rspec'
gem 'capybara'
gem 'factory_girl_rails', '~> 4.4.1'
......@@ -77,6 +75,7 @@ group :development, :test do
gem 'database_cleaner'
gem 'shoulda-matchers'
gem "turnip"
gem 'selenium-webdriver'
gem 'rspec-core'
gem 'rspec-expectations'
gem 'rspec-mocks'
......
......@@ -77,6 +77,8 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
childprocess (0.5.6)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.0)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
......@@ -121,6 +123,7 @@ GEM
railties (>= 3.0.0)
faker (1.4.3)
i18n (~> 0.5)
ffi (1.9.10)
figaro (1.1.1)
thor (~> 0.14)
font-awesome-sass (4.3.2.1)
......@@ -221,6 +224,7 @@ GEM
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.4)
rubyzip (1.1.7)
sass (3.4.16)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
......@@ -231,6 +235,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
selenium-webdriver (2.46.2)
childprocess (~> 0.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
slim (3.0.6)
......@@ -276,6 +285,7 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket (1.2.2)
will_paginate (3.0.7)
xpath (2.0.0)
nokogiri (~> 1.3)
......@@ -319,6 +329,7 @@ DEPENDENCIES
rspec-support
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
selenium-webdriver
shoulda-matchers
slim
spring
......
class ProductsController < ApplicationController
before_action :get_categories
before_action :authenticate_user!, only: [:new, :create]
add_breadcrumb "Home", :root_path
......
......@@ -4,4 +4,4 @@
= render partial: "products/item", collection: @products, as: :product
.text-center
= paginate @products
\ No newline at end of file
= will_paginate @products
\ No newline at end of file
ul.list-group
.list-group.nav-categories
- @categories.each do |cate|
= link_to cate.name, category_path(cate), class: "list-group-item #{@category.try(:id)==cate.id ? 'active' : ''}"
\ No newline at end of file
Feature: Cart show - Add to cart - Checkout
Background:
Given I regitered with name "test", email "test@gmail.com", password "abc123456"
Scenario: Not login Add to cart should redirect to login page
Given I go to product page have "2" items in stock
When I press "Add to cart"
Then I should see "Log in"
Scenario: Logined - Add to cart
Given I logined with email "test@gmail.com" and password "abc123456"
And I go to product page have "2" items in stock
When I press "Add to cart"
Then I should see "Add to cart successfully"
When I press "Add to cart"
Then I should see "Add to cart successfully"
When I press "Add to cart"
Then I should see "Product is not enough in stock"
When I go to cart page
Then I should see "Checkout"
When I click "Checkout"
Then I should see "Checkout successfully"
Feature: List - show product
Scenario: List products
When I go to home page
Then I should see "Products"
And I should see list products
And I should see recommend products
And I should see menu categories
When I click first menu
Then I should see the first menu highlight
And I should see list products of first menu
When I click first product
Then I should see "Item ID"
\ No newline at end of file
module CategorySteps
step "I should see menu categories" do
page.all(".nav-categories a").count.should == ::Category.count
end
step "I click first menu" do
page.first(".nav-categories a").click
end
step "I should see the first menu highlight" do
(page.first(".nav-categories a")['class'].include?("active")).should == true
end
step "I should see list products of first menu" do
cate = page.first(".nav-categories a").text
page.all(".products .row").each do |row_tag|
::Product.where(title: row_tag.find(".title a").text).first.category.name.should == cate
end
end
end
RSpec.configure do |c|
c.include CategorySteps, :type => :feature
end
module HelperSteps
# include Rails.application.routes.url_helpers
step "there is a monster" do
puts "11111111"
# Url --------------------------------------------------------------------------
step "I go to home page" do
visit root_path
end
step "I go to register page" do
visit root_path
visit new_user_registration_path
end
step "I go to sign in page" do
visit new_user_session_path
end
step "I go to cart page" do
visit cart_path
end
step "I go to product page have :amount items in stock" do |amount|
p = ::Product.first
p.update_columns(stock: amount)
visit product_path(p)
end
step "I go to new product page" do
visit new_product_path
end
step "I attach :field with default image" do |field|
attach_file field, "spec/support/uploads/logo.png"
end
# Common ----------------------------------------------------------------------------
step "I enter :value into :field field" do |value, field|
value = value.gsub("_uniq", Time.now.to_i.to_s)
fill_in(field, with: value)
end
......@@ -16,12 +41,24 @@ module HelperSteps
click_button(btn)
end
step "I click :link" do |link|
first(:link, link).click
end
step "I should see :text" do |text|
page.should(have_content(text))
end
step "I should (not)? see :text" do |negate, text|
within('body') do
negate ? page.should_not(have_content(text)) : page.should(have_content(text))
end
end
step "I should see value of :tag is :value" do |tag, value|
page.first(tag).value().should == value
end
end
RSpec.configure do |c|
......
module ProductSteps
step "I should see list products" do
amount = [::Product.count, ENV["default_perpage"].to_i].min
page.all(".products .row").count.should == amount
end
step "I should see recommend products" do
page.all(".recommends .col-sm-4").count.should == ::Product.recommend.count
end
step "I click first product" do
page.first(".products a").click
end
end
RSpec.configure do |c|
c.include ProductSteps, :type => :feature
end
module UserSteps
step "I logined with email :email and password :pass" do |email, pass|
visit new_user_session_path
step "I login with email '#{email}' and password '#{pass}'"
# fill_in("user_email", with: email)
# fill_in("user_password", with: pass)
# click_button("Log in")
end
step "I login with email :email and password :pass" do |email, pass|
fill_in("user_email", with: email)
fill_in("user_password", with: pass)
click_button("Log in")
end
step "I regitered with name :name, email :email, password :pass" do |name, email, pass|
u = ::User.where(name: name, email: email).first
if u.blank?
u = ::User.create(name: name, email: email, password: pass)
else
u.update_attributes(password: pass)
end
end
end
RSpec.configure do |c|
c.include UserSteps, :type => :feature
end
Feature: User create product
Background:
Given I regitered with name "test", email "test@gmail.com", password "abc123456"
Scenario: Not login Add to cart should redirect to login page
Given I go to new product page
Then I should see "Log in"
Scenario: Logined - create project
Given I logined with email "test@gmail.com" and password "abc123456"
And I go to new product page
Then I enter "product_uniq" into "product_pid" field
And I enter "title_uniq" into "product_title" field
And I enter "product_uniq" into "product_pid" field
And I enter "10" into "product_stock" field
And I enter "product_author" into "product_author" field
And I enter "product_publisher" into "product_publisher" field
And I enter "product_studio" into "product_studio" field
And I enter "10" into "product_price" field
And I attach "Image" with default image
When I press "Save"
Feature: User sign in, then logout
Background:
Given I regitered with name "test", email "test@gmail.com", password "abc123456"
Given I go to sign in page
Scenario: login no email, no password
When I press 'Log in'
Then I should see "Log in"
@selenium
Scenario: login successfully then logout
When I login with email "test@gmail.com" and password "abc123456"
Then I should see "Logout"
When I click "Logout"
Then I should see "Login"
Feature: User register
Scenario: register with no name
When I go to register page
Then I enter abc@gmail.com into email field
And I enter abc123456 into password field
Background:
Given I go to register page
Scenario: register no name, no email, no password
When I press 'Sign up'
Then I should see error
Then I should see "Sign up"
Scenario: register password too short
Then I enter "abc_uniq" into "user_name" field
And I enter "abc_uniq@gmail.com" into "user_email" field
And I enter "a" into "user_password" field
And I enter "a" into "user_password_confirmation" field
When I press 'Sign up'
Then I should see "Sign up"
Scenario: register password confirm not match
Then I enter "abc_uniq" into "user_name" field
And I enter "abc_uniq@gmail.com" into "user_email" field
And I enter "abc123456" into "user_password" field
And I enter "abc1" into "user_password_confirmation" field
When I press 'Sign up'
Then I should see "Sign up"
Scenario: register invalid email
Then I enter "abc_uniq" into "user_name" field
And I enter "abc_uniq@gmail" into "user_email" field
And I enter "abc123456" into "user_password" field
And I enter "abc123456" into "user_password_confirmation" field
When I press 'Sign up'
Then I should see "Sign up"
Scenario: register successfully
Then I enter "abc_uniq" into "user_name" field
And I enter "abc_uniq@gmail.com" into "user_email" field
And I enter "abc123456" into "user_password" field
And I enter "abc123456" into "user_password_confirmation" field
When I press 'Sign up'
Then I should see "Logout"
\ No newline at end of file
......@@ -12,24 +12,25 @@
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'factory_girl_rails'
require "action_mailer"
require "email_spec"
require 'database_cleaner'
# require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
# require 'capybara/rails'
require 'turnip/capybara'
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.include Warden::Test::Helpers
config.before :suite do
Warden.test_mode!
end
# config.include(EmailSpec::Helpers)
# config.include(EmailSpec::Matchers)
......@@ -93,6 +94,5 @@ RSpec.configure do |config|
mocks.verify_partial_doubles = true
end
=end
binding.pry
config.include Rails.application.routes.url_helpers
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment