Commit decfe395 authored by Huynh Nguyen V's avatar Huynh Nguyen V
Browse files

fix test category index

Showing with 17 additions and 34 deletions
+17 -34
......@@ -15,6 +15,7 @@ gem "tux"
gem 'sinatra-formhelpers-ng'
gem 'faker'
gem 'will_paginate', '~> 3.0'
gem 'nokogiri', '~> 1.6', '>= 1.6.8'
group :test do
gem 'rspec'
......
......@@ -5,44 +5,22 @@ RSpec.describe "categories", type: :controller do
def app
CategoryController.new
end
before :each do
@category = create :category
end
context "index categories" do
it 'success' do
get "/categories"
expect(last_response).to be_ok
end
end
context "create category" do
it "success" do
it 'should return success response' do
get "/categories"
expect(last_response).to be_ok
end
end
context "show category" do
it "success" do
get "/categories/#{@category.id}"
expect(last_response).to be_ok
end
end
context "edit category" do
it "success" do
get "/categories/#{@category.id}/edit"
@category = attributes_for(:category)
expect(last_response).to be_ok
expect(last_response.status).to eq 200
end
end
context "delete category" do
it "success" do
delete "/categories/#{@category.id}"
it 'should to list count page one' do
create_list :category, 2
get "/categories"
expect(last_response).to be_ok
doc = Nokogiri::HTML(last_response.body)
array_category = []
doc.css('.name').each do |l|
array_category << l.content
end
expect(array_category.length).to eq 2
end
end
end
FactoryBot.define do
factory :category do |f|
f.name { Faker::Name.name }
factory :category do
sequence(:name) { |n| Faker::Name.name }
end
end
......@@ -4,12 +4,15 @@ require "rack/test"
require './config/environment'
require 'factory_bot'
require 'database_cleaner'
require 'nokogiri'
require 'open-uri'
DatabaseCleaner.strategy = :truncation
module RSpecMixin
include Rack::Test::Methods
include FactoryBot::Syntax::Methods
include WillPaginate::Sinatra::Helpers
def app
Sinatra::Application
end
......@@ -27,4 +30,5 @@ RSpec.configure do |config|
DatabaseCleaner.clean
end
config.shared_context_metadata_behavior = :apply_to_host_groups
%w(will_paginate will_paginate/active_record).each {|lib| require lib}
end
Supports Markdown
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