Cucumber tests are now running, only a few passing, most fail.

This commit is contained in:
Mario Visic 2011-12-06 22:46:21 +08:00
parent a76020108f
commit 264ba8ebf2
6 changed files with 35 additions and 85 deletions

View File

@ -5,7 +5,7 @@ Given /^I am not authenticated$/ do
end end
Given /^I am an authenticated "([^"]*)"$/ do |role| Given /^I am an authenticated "([^"]*)"$/ do |role|
@member = Site.first.memberships.where(:role => role.downcase).first || FactoryGirl.create(role.downcase.to_sym, :site => Site.first) @member = Locomotive::Site.first.memberships.where(:role => role.downcase).first || FactoryGirl.create(role.downcase.to_sym, :site => Locomotive::Site.first)
step %{I go to login} step %{I go to login}
step %{I fill in "Email" with "#{@member.account.email}"} step %{I fill in "Email" with "#{@member.account.email}"}

View File

@ -1,5 +1,5 @@
Given %r{^I have a custom model named "([^"]*)" with$} do |name, fields| Given %r{^I have a custom model named "([^"]*)" with$} do |name, fields|
site = Site.first site = Locomotive::Site.first
content_type = FactoryGirl.build(:content_type, :site => site, :name => name) content_type = FactoryGirl.build(:content_type, :site => site, :name => name)
fields.hashes.each do |field| fields.hashes.each do |field|
if (target_name = field.delete('target')).present? if (target_name = field.delete('target')).present?
@ -14,7 +14,7 @@ Given %r{^I have a custom model named "([^"]*)" with$} do |name, fields|
end end
Given /^I set up a reverse has_many relationship between "([^"]*)" and "([^"]*)"$/ do |name_1, name_2| Given /^I set up a reverse has_many relationship between "([^"]*)" and "([^"]*)"$/ do |name_1, name_2|
site = Site.first site = Locomotive::Site.first
content_type_1 = site.content_types.where(:name => name_1).first content_type_1 = site.content_types.where(:name => name_1).first
content_type_2 = site.content_types.where(:name => name_2).first content_type_2 = site.content_types.where(:name => name_2).first
@ -30,7 +30,7 @@ Given /^I set up a reverse has_many relationship between "([^"]*)" and "([^"]*)"
end end
Given %r{^I have "([^"]*)" as "([^"]*)" values of the "([^"]*)" model$} do |values, field, name| Given %r{^I have "([^"]*)" as "([^"]*)" values of the "([^"]*)" model$} do |values, field, name|
content_type = ContentType.where(:name => name).first content_type = Locomotive::ContentType.where(:name => name).first
field = content_type.contents_custom_fields.detect { |f| f.label == field } field = content_type.contents_custom_fields.detect { |f| f.label == field }
field.should_not be_nil field.should_not be_nil
@ -45,7 +45,7 @@ Given %r{^I have "([^"]*)" as "([^"]*)" values of the "([^"]*)" model$} do |valu
end end
Given %r{^I have entries for "([^"]*)" with$} do |name, entries| Given %r{^I have entries for "([^"]*)" with$} do |name, entries|
content_type = ContentType.where(:name => name).first content_type = Locomotive::ContentType.where(:name => name).first
entries.hashes.each do |entry| entries.hashes.each do |entry|
content_type.contents.create(entry) content_type.contents.create(entry)
end end
@ -53,7 +53,7 @@ Given %r{^I have entries for "([^"]*)" with$} do |name, entries|
end end
When %r{^I change the presentation of the "([^"]*)" model by grouping items by "([^"]*)"$} do |name, field| When %r{^I change the presentation of the "([^"]*)" model by grouping items by "([^"]*)"$} do |name, field|
content_type = ContentType.where(:name => name).first content_type = Locomotive::ContentType.where(:name => name).first
field = content_type.contents_custom_fields.detect { |f| f.label == field } field = content_type.contents_custom_fields.detect { |f| f.label == field }
content_type.group_by_field_name = field._name content_type.group_by_field_name = field._name
content_type.save.should be_true content_type.save.should be_true

View File

@ -1,4 +1,4 @@
# Creates a Site record # Creates a Locomotive::Site record
# #
# examples: # examples:
# - I have the site: "some site" set up # - I have the site: "some site" set up
@ -18,12 +18,12 @@ Given /^I have a site set up$/ do
end end
Given /^I have a designer and an author$/ do Given /^I have a designer and an author$/ do
FactoryGirl.create(:designer, :site => Site.first) FactoryGirl.create(:designer, :site => Locomotive::Site.first)
FactoryGirl.create(:author, :site => Site.first) FactoryGirl.create(:author, :site => Locomotive::Site.first)
end end
Then /^I should be a administrator of the "([^"]*)" site$/ do |name| Then /^I should be a administrator of the "([^"]*)" site$/ do |name|
site = Site.where(:name => name).first site = Locomotive::Site.where(:name => name).first
m = site.memberships.detect { |m| m.account_id == @admin._id && m.admin? } m = site.memberships.detect { |m| m.account_id == @admin._id && m.admin? }
m.should_not be_nil m.should_not be_nil
end end

View File

@ -5,14 +5,15 @@
# files. # files.
ENV['RAILS_ENV'] ||= 'test' ENV['RAILS_ENV'] ||= 'test'
ENV["RAILS_ROOT"] ||= File.join(File.dirname(__FILE__), '../', '../', 'spec', 'dummy')
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/rails' require 'cucumber/rails'
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
require 'cucumber/rails/rspec' require 'cucumber/rails/rspec'
require 'cucumber/rails/world' require 'cucumber/rails/world'
require 'factory_girl'
require 'capybara' require 'capybara'
require 'capybara/rails' require 'capybara/rails'
require 'capybara/cucumber' require 'capybara/cucumber'
@ -67,4 +68,6 @@ ActionController::Base.allow_rescue = false
require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/carrierwave') require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/carrierwave')
require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/locomotive') require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/locomotive')
World(Locomotive::Engine.routes.url_helpers) # Load engine routes
Locomotive.configure_for_test(true) Locomotive.configure_for_test(true)

View File

@ -1,4 +1,6 @@
module NavigationHelpers module NavigationHelpers
include Locomotive::Engine.routes.url_helpers # Load engine routes
# Maps a name to a path. Used by the # Maps a name to a path. Used by the
# #
# When /^I go to (.+)$/ do |page_name| # When /^I go to (.+)$/ do |page_name|
@ -11,35 +13,35 @@ module NavigationHelpers
when /the home\s?page$/ when /the home\s?page$/
'/' '/'
when /login/ when /login/
new_admin_session_path new_locomotive_account_session_path
when /logout/ when /logout/
destroy_admin_session_path destroy_locomotive_account_session_url
when /pages( list)?/ when /pages( list)?/
admin_pages_path locomotive_pages_path
when /new page/ when /new page/
new_admin_page_path new_locomotive_page_path
when /"(.*)" edition page/ when /"(.*)" edition page/
page = Site.first.pages.where(:slug => $1).first page = Site.first.pages.where(:slug => $1).first
edit_admin_page_path(page) edit_locomotive_page_path(page)
when /theme assets/ when /theme assets/
admin_theme_assets_path locomotive_theme_assets_path
when /site settings/ when /site settings/
edit_admin_current_site_path edit_locomotive_current_site_path
when /account settings/ when /account settings/
edit_admin_my_account_path edit_locomotive_my_account_path
when /import page/ when /import page/
new_admin_import_path new_locomotive_import_path
when /export page/ when /export page/
new_admin_export_path new_locomotive_export_path
when /the "(.*)" model list page/ when /the "(.*)" model list page/
content_type = Site.first.content_types.where(:name => $1).first content_type = Locomotive::Site.first.content_types.where(:name => $1).first
admin_contents_path(content_type.slug) locomotive_contents_path(content_type.slug)
when /the "(.*)" model creation page/ when /the "(.*)" model creation page/
content_type = Site.first.content_types.where(:name => $1).first content_type = Locomotive::Site.first.content_types.where(:name => $1).first
new_admin_content_path(content_type.slug) new_locomotive_content_path(content_type.slug)
when /the "(.*)" model edition page/ when /the "(.*)" model edition page/
content_type = Site.first.content_types.where(:name => $1).first content_type = Locomotive::Site.first.content_types.where(:name => $1).first
edit_admin_content_type_path(content_type) edit_locomotive_content_type_path(content_type)
# Add more mappings here. # Add more mappings here.
# Here is an example that pulls values out of the Regexp: # Here is an example that pulls values out of the Regexp:
@ -61,58 +63,3 @@ module NavigationHelpers
end end
World(NavigationHelpers) World(NavigationHelpers)
# module NavigationHelpers
# # Maps a name to a path. Used by the
# #
# # When /^I go to (.+)$/ do |page_name|
# #
# # step definition in web_steps.rb
# #
# def path_to(page_name)
# case page_name
#
# when /the home\s?page/
# '/'
# when /login/
# new_admin_session_path
# when /logout/
# destroy_admin_session_path
# when /pages( list)?/
# admin_pages_path
# when /new page/
# new_admin_page_path
# when /"(.*)" edition page/
# page = Site.first.pages.where(:slug => $1).first
# edit_admin_page_path(page)
# when /theme assets/
# admin_theme_assets_path
# when /site settings/
# edit_admin_current_site_path
# when /import page/
# new_admin_import_path
# when /the "(.*)" model edition page/
# content_type = Site.first.content_types.where(:name => $1).first
# edit_admin_content_type_path(content_type)
#
# # Add more mappings here.
# # Here is an example that pulls values out of the Regexp:
# #
# # when /^(.*)'s profile page$/i
# # user_profile_path(User.find_by_login($1))
#
# else
# begin
# page_name =~ /the (.*) page/
# path_components = $1.split(/\s+/)
# self.send(path_components.push('path').join('_').to_sym)
# rescue Object => e
# raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
# "Now, go and add a mapping in #{__FILE__}"
# end
# end
# end
# end
#
# World(NavigationHelpers)