Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

general upgrade and 1.9.3 compat

  • Loading branch information...
commit 68cb0588d85e53da3fd850600197a077048c8139 1 parent 7427213
@mhfs authored
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
1  Capfile
@@ -45,4 +45,3 @@ end
after 'deploy:update_code', 'deploy:symlink_tmp'
after 'deploy:setup', 'deploy:setup_tmp'
-
View
6 Gemfile
@@ -1,13 +1,19 @@
source 'http://gemcutter.org'
+gem 'rake'
gem 'rack', '1.2.1'
gem 'unicorn'
gem 'sinatra'
gem 'haml'
gem 'faker'
+group :development do
+ gem 'pry'
+end
+
group :test do
gem 'rspec'
gem 'rack-test'
gem 'capybara'
+ gem 'capybara-webkit'
end
View
75 Gemfile.lock
@@ -1,49 +1,78 @@
GEM
remote: http://gemcutter.org/
specs:
- capybara (0.3.9)
- culerity (>= 0.2.4)
+ capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
- selenium-webdriver (>= 0.0.3)
- culerity (0.2.12)
- faker (1.0.0)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ capybara-webkit (0.11.0)
+ capybara (>= 1.0.0, < 1.2)
+ json
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
+ coderay (1.0.5)
+ diff-lcs (1.1.3)
+ faker (1.0.1)
i18n (~> 0.4)
- ffi (0.6.3)
- rake (>= 0.8.7)
- haml (3.0.17)
+ ffi (1.0.11)
+ haml (3.1.4)
i18n (0.6.0)
- json_pure (1.4.6)
- kgio (2.1.1)
- mime-types (1.16)
- nokogiri (1.4.3.1)
+ json (1.6.6)
+ kgio (2.7.4)
+ method_source (0.7.1)
+ mime-types (1.18)
+ multi_json (1.2.0)
+ nokogiri (1.5.2)
+ pry (0.9.8.4)
+ coderay (~> 1.0.5)
+ method_source (~> 0.7.1)
+ slop (>= 2.4.4, < 3)
rack (1.2.1)
- rack-test (0.5.4)
+ rack-test (0.6.1)
rack (>= 1.0)
- rake (0.8.7)
- rspec (1.3.0)
- rubyzip (0.9.4)
- selenium-webdriver (0.0.28)
- ffi (>= 0.6.1)
- json_pure
+ raindrops (0.8.0)
+ rake (0.9.2.2)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ rubyzip (0.9.6.1)
+ selenium-webdriver (2.20.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ multi_json (~> 1.0)
rubyzip
- sinatra (1.0)
- rack (>= 1.0)
- unicorn (3.2.1)
- kgio (~> 2.1)
+ sinatra (1.2.8)
+ rack (~> 1.1)
+ tilt (>= 1.2.2, < 2.0)
+ slop (2.4.4)
+ tilt (1.3.3)
+ unicorn (4.2.1)
+ kgio (~> 2.6)
rack
+ raindrops (~> 0.7)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
capybara
+ capybara-webkit
faker
haml
+ pry
rack (= 1.2.1)
rack-test
+ rake
rspec
sinatra
unicorn
View
6 Rakefile
@@ -1,6 +0,0 @@
-require 'spec/rake/spectask'
-
-desc "Run all specs"
-Spec::Rake::SpecTask.new do |t|
- t.spec_opts = %w(--format specdoc --color)
-end
View
4 application.rb
@@ -1,3 +1,7 @@
+# encoding: UTF-8
+
+$:.unshift File.dirname(__FILE__)
+
# Gems requires
require 'rubygems'
require 'sinatra'
View
1  config/unicorn.rb
@@ -30,4 +30,3 @@
if GC.respond_to?(:copy_on_write_friendly=)
GC.copy_on_write_friendly = true
end
-
View
7 lib/company.rb
@@ -1,5 +1,4 @@
class Company < Entity
-
def valid?
clean = document.gsub(/[a-zA-Z\.\(\)\/\-|\s]/,'')
return false unless clean.length == 14
@@ -38,8 +37,8 @@ def verification_digit_for(known_digits)
end
def format_number(array)
- array.to_s =~ /(\d{2})\.?(\d{3})\.?(\d{3})\/?(\d{4})-?(\d{2})/
+ array = array.join if array.is_a?(Array)
+ array =~ /(\d{2})\.?(\d{3})\.?(\d{3})\/?(\d{4})-?(\d{2})/
"#{$1}.#{$2}.#{$3}/#{$4}-#{$5}"
end
-
-end
+end
View
3  lib/entity.rb
@@ -5,5 +5,4 @@ def initialize(doc = nil)
self.document = doc.nil? ? generate_document : doc
self.name = generate_name
end
-
-end
+end
View
2  lib/helpers.rb
@@ -1,5 +1,4 @@
helpers do
-
def javascript_include_tag(*scripts)
tags = []
scripts.each do |script|
@@ -85,5 +84,4 @@ def clippy(element_id, bgcolor='#FFFFFF')
</object>
EOF
end
-
end
View
7 lib/person.rb
@@ -1,5 +1,4 @@
class Person < Entity
-
def valid?
clean = document.gsub(/[a-zA-Z\.\(\)\/\-|\s]/,'')
return false unless clean.length == 11
@@ -37,8 +36,8 @@ def verification_digit_for(known_digits)
end
def format_number(array)
- array.to_s =~ /(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})/
+ array = array.join if array.is_a?(Array)
+ array =~ /(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})/
"#{$1}.#{$2}.#{$3}-#{$4}"
end
-
-end
+end
View
55 spec/application_spec.rb
@@ -1,9 +1,8 @@
+# encoding: UTF-8
require 'spec_helper'
describe Sinatra::Application do
-
context "Homepage" do
-
before do
visit '/'
end
@@ -19,59 +18,45 @@
it "should display validation form" do
page.should have_css('form#validate')
end
-
end
context "About" do
-
it "should show page" do
visit '/about'
page.should have_css('h2', :text => 'Sobre')
end
-
end
context "Document Validation" do
+ it "should require a document", :js => true do
+ visit '/'
+ click_button 'Vai!'
- it "should require a document" do
- using_javascript do
- visit '/'
- click 'Vai!'
-
- page.should have_css('div#validate_response div.notice', :text => 'Informe o CPF ou CNPJ.')
- end
+ page.should have_css('div#validate_response div.notice', :text => 'Informe o CPF ou CNPJ.')
end
- it "should complain about invalid document" do
- using_javascript do
- visit '/'
- fill_in 'document', :with => '123456'
- click 'Vai!'
+ it "should complain about invalid document", :js => true do
+ visit '/'
+ fill_in 'document', :with => '123456'
+ click_button 'Vai!'
- page.should have_css('div#validate_response div.error', :text => 'Documento inválido.')
- end
+ page.should have_css('div#validate_response div.error', :text => 'Documento inválido.')
end
- it "should accept valid CNPJ" do
- using_javascript do
- visit '/'
- fill_in 'document', :with => '24.221.361/0001-26'
- click 'Vai!'
+ it "should accept valid CNPJ", :js => true do
+ visit '/'
+ fill_in 'document', :with => '24.221.361/0001-26'
+ click_button 'Vai!'
- page.should have_css('div#validate_response div.success', :text => 'CNPJ Válido.')
- end
+ page.should have_css('div#validate_response div.success', :text => 'CNPJ Válido.')
end
- it "should accept valid CPF" do
- using_javascript do
- visit '/'
- fill_in 'document', :with => '203.850.773-27'
- click 'Vai!'
+ it "should accept valid CPF", :js => true do
+ visit '/'
+ fill_in 'document', :with => '203.850.773-27'
+ click_button 'Vai!'
- page.should have_css('div#validate_response div.success', :text => 'CPF Válido.')
- end
+ page.should have_css('div#validate_response div.success', :text => 'CPF Válido.')
end
-
end
-
end
View
2  spec/company_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe Company do
-
subject { Company.new }
it "should respond to name and document" do
@@ -33,5 +32,4 @@
Company.new('123456').should_not be_valid
Company.new('').should_not be_valid
end
-
end
View
2  spec/person_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe Person do
-
subject { Person.new }
it "should respond to name and document" do
@@ -33,5 +32,4 @@
Person.new('123456').should_not be_valid
Person.new('').should_not be_valid
end
-
end
View
18 spec/spec_helper.rb
@@ -1,14 +1,16 @@
require File.join(File.dirname(__FILE__), '..', 'application.rb')
-require 'spec'
+require 'rspec'
require 'rack/test'
require 'capybara'
-require 'capybara/dsl'
+require 'capybara/rspec'
+require 'capybara/webkit'
require 'net/http'
+require 'pry'
-Spec::Runner.configure do |conf|
+RSpec.configure do |conf|
conf.include Rack::Test::Methods
- conf.include Capybara
+ conf.include Capybara::DSL
end
def app
@@ -17,10 +19,4 @@ def app
Capybara.app = app
Capybara.default_selector = :css
-
-def using_javascript(driver = :selenium)
- Capybara.current_driver = driver
- yield
-ensure
- Capybara.use_default_driver
-end
+Capybara.javascript_driver = :webkit
Please sign in to comment.
Something went wrong with that request. Please try again.