Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cucumber

  • Loading branch information...
commit 4cf713a7b2421f4ecc6b1a41ad6e8842b03f27b7 1 parent 3c7ba41
Danilo Lima authored
View
7 Gemfile
@@ -39,6 +39,13 @@ gem 'heroku'
gem 'factory_girl_rails'
+group :test, :development do
+ gem 'spork'
+ gem 'simplecov'
+ gem 'guard-spork'
+ gem 'guard-rspec'
+end
+
group :development do
gem 'rspec-rails', '2.6.1'
gem 'ruby-debug19'
View
17 Gemfile.lock
@@ -72,6 +72,14 @@ GEM
ffi (1.0.11)
gherkin (2.7.7)
json (>= 1.4.6)
+ guard (1.0.0)
+ ffi (>= 0.5.0)
+ thor (~> 0.14.6)
+ guard-rspec (0.6.0)
+ guard (>= 0.10.0)
+ guard-spork (0.5.2)
+ guard (>= 0.10.0)
+ spork (>= 0.8.4)
heroku (2.20.0)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
@@ -159,6 +167,11 @@ GEM
ffi (~> 1.0.9)
multi_json (~> 1.0.4)
rubyzip
+ simplecov (0.6.1)
+ multi_json (~> 1.0)
+ simplecov-html (~> 0.5.3)
+ simplecov-html (0.5.3)
+ spork (0.9.0)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -186,6 +199,8 @@ DEPENDENCIES
cucumber-rails
database_cleaner
factory_girl_rails
+ guard-rspec
+ guard-spork
heroku
jquery-rails
mysql2
@@ -195,4 +210,6 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
selenium-client
selenium-webdriver
+ simplecov
+ spork
uglifier (>= 1.0.3)
View
30 Guardfile
@@ -0,0 +1,30 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
+ watch('config/application.rb')
+ watch('config/environment.rb')
+ watch(%r{^config/environments/.+\.rb$})
+ watch(%r{^config/initializers/.+\.rb$})
+ watch('config/config.yml')
+ watch('Gemfile')
+ watch('Gemfile.lock')
+ watch('spec/spec_helper.rb') { :rspec }
+ watch('test/test_helper.rb') { :test_unit }
+ watch(%r{features/support/}) { :cucumber }
+end
+
+guard 'rspec', :version => 2, :cli => '--drb' do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+ watch('config/config.yml') { "spec" }
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+ watch(%r{^spec/factories/(.*)(_factory)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
+end
View
2  app/views/books/index.html.erb
@@ -14,7 +14,7 @@
<td><%= book.title %></td>
<td><%= book.description %></td>
<td><%= link_to 'Show', book %></td>
- <td><%= link_to 'Edit', edit_book_path(book) %></td>
+ <td><%= link_to 'Edit', edit_book_path(book), {:id => "Edit"} %></td>
<td><%= link_to 'Destroy', book, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
View
20 features/books.feature
@@ -1,12 +1,16 @@
@javascript
Feature: Books
As an User
- I want to insert books
-
-@javascript
-Scenario: Inserting a valid book
+ I want to manage books
+
+
+ @javascript
+Scenario: Editing a valid book
Given I am a user on the the books listing page
- When I follow "New Book"
- And I fill with valid book data
- And I press "Create Book"
- Then I should see "Book was successfully created."
+ When I follow "Edit"
+ And I fill in title with "O alquimista - Nova edicao"
+ And I fill in description with "Livro de Paulo Coelho - Nova edicao"
+ And I press "Update Book"
+ Then I should see "Book was successfully updated."
+ And I should see title with value "O alquimista - Nova edicao"
+ And I should see description with value "Livro de Paulo Coelho"
View
23 features/step_definitions/book_steps.rb
@@ -1,20 +1,25 @@
-
Given /^I am a user on the the books listing page$/ do
visit books_path
end
-
When /^I follow "([^"]*)"$/ do |arg1|
+ save_and_open_page
click_link arg1
end
-
-When /^I fill with valid book data$/ do
- Book.create("livro teste")
+When /^I fill in title with "([^"]*)"$/ do |arg1|
+ fill_in('Title', :with => arg1)
+end
+When /^I fill in description with "([^"]*)"$/ do |arg1|
+ fill_in('Description', :with => arg1)
end
-
When /^I press "([^"]*)"$/ do |arg1|
- pending # express the regexp above with the code you wish you had
+ click_button arg1
end
-
Then /^I should see "([^"]*)"$/ do |arg1|
- pending # express the regexp above with the code you wish you had
+ page.should have_content(arg1)
+end
+Then /^I should see title with value "([^"]*)"$/ do |arg1|
+ page.should have_content(arg1)
end
+Then /^I should see description with value "([^"]*)"$/ do |arg1|
+ page.should have_content(arg1)
+end
View
102 spec/spec_helper.rb
@@ -1,31 +1,73 @@
-# This file is copied to spec/ when you run 'rails generate rspec:install'
-ENV["RAILS_ENV"] ||= 'test'
-require File.expand_path("../../config/environment", __FILE__)
-require 'rspec/rails'
-
-# Add this to load Capybara integration:
-require 'capybara/rspec'
-require 'capybara/rails'
-
-# Requires supporting ruby files with custom matchers and macros, etc,
-# in spec/support/ and its subdirectories.
-Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
-
-RSpec.configure do |config|
- # == Mock Framework
- #
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
- #
- # config.mock_with :mocha
- # config.mock_with :flexmock
- # config.mock_with :rr
- config.mock_with :rspec
-
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
-
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
- # examples within a transaction, remove the following line or assign false
- # instead of true.
- config.use_transactional_fixtures = true
+require 'rubygems'
+require 'spork'
+require "active_record"
+
+
+
+Spork.prefork do
+ # Loading more in this block will cause your tests to run faster. However,
+ # if you change any configuration or code from libraries loaded here, you'll
+ # need to restart spork for it take effect.
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
+ ENV["RAILS_ENV"] ||= 'test'
+
+ require 'simplecov'
+ SimpleCov.start 'rails'
+
+ require File.expand_path("../../config/environment", __FILE__)
+ require 'rspec/rails'
+ require 'rspec/autorun'
+
+ # Requires supporting ruby files with custom matchers and macros, etc,
+ # in spec/support/ and its subdirectories.
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+ RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ # config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ # config.infer_base_class_for_anonymous_controllers = false
+
+ require 'database_cleaner'
+ config.before(:suite) do
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
+ load File.expand_path("../../db/schema.rb", __FILE__)
+ DatabaseCleaner[:active_record].strategy = :truncation
+ DatabaseCleaner[:mongoid].strategy = :truncation
+ #DatabaseCleaner.clean_with(:truncation)
+ end
+
+ config.before(:each) do
+ DatabaseCleaner.start
+ end
+
+ config.after(:each) do
+ DatabaseCleaner.clean
+ end
+
+ config.include FactoryGirl::Syntax::Methods
+ end
+end
+
+Spork.each_run do
+ # This code will be run each time you run your specs.
+ FactoryGirl.reload
end
+
Please sign in to comment.
Something went wrong with that request. Please try again.