Skip to content

Commit

Permalink
Added tests with real capybara nodes
Browse files Browse the repository at this point in the history
Signed-off-by: hajee <hajee@moretIA.com>
  • Loading branch information
hajee authored and Bert Hajee committed Jun 14, 2013
1 parent 9926b9f commit 4301e5c
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 134 deletions.
10 changes: 9 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ GEM
i18n (0.6.1)
mime-types (1.23)
mini_portile (0.5.0)
multi_json (1.7.6)
multi_json (1.7.7)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
rack (1.5.2)
rack-protection (1.5.0)
rack
rack-test (0.6.2)
rack (>= 1.0)
rake (10.0.4)
Expand All @@ -49,7 +51,12 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
sinatra (1.3.6)
rack (~> 1.4)
rack-protection (~> 1.3)
tilt (~> 1.3, >= 1.3.3)
thor (0.18.1)
tilt (1.4.1)
xpath (2.0.0)
nokogiri (~> 1.3)

Expand All @@ -62,3 +69,4 @@ DEPENDENCIES
page_record!
rake
rspec
sinatra
11 changes: 0 additions & 11 deletions lib/page_record/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ def self.undefine_accessor_methods(base)
end
end

def self.undefine_class_methods(base)
eigenclass = class << base; self; end
attributes = base.instance_variable_get('@attributes')
eigenclass.instance_eval do
attributes.each do | attribute|
remove_method "find_by_#{attribute}"
end
end
end



def self.define_instance_methods(base)
define_accessor_methods(base)
Expand Down
1 change: 1 addition & 0 deletions page_record.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "sinatra"
# spec.add_development_dependency "debugger"

spec.add_dependency "capybara" , '~>2.1.0'
Expand Down
22 changes: 19 additions & 3 deletions spec/page_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ class TeamPage < PageRecord::PageRecord; end
PageRecord::PageRecord.page = page
end

describe ".type" do

before do
class CamelCase
def self.attribute_names
[ 'id' , 'name', 'points', 'ranking', 'goals']
end
end
class CamelCasePage < PageRecord::PageRecord; end
end

it "returns the internal type of the class" do
expect( CamelCasePage.type).to eq "camel_case"
end

end


describe ".attributes" do
before do
Expand Down Expand Up @@ -317,7 +334,7 @@ class TeamPage < PageRecord::PageRecord
context "attribute is on page" do

it "returns the dom object" do
expect( subject.name?.class).to eq Capybara::Node::Simple
expect( subject.name?.class).to eq Capybara::Node::Element
end
end

Expand Down Expand Up @@ -363,7 +380,6 @@ class TeamPage < PageRecord::PageRecord
include_context "page one record in a form"

it "sets the attribute to specified value" do
pending
expect{subject}.to change{record.name}.from(nil).to('FC Utrecht')
end
end
Expand All @@ -388,7 +404,7 @@ class TeamPage < PageRecord::PageRecord
subject {record.create}

it "clicks on the specified action element" do
pending "waits for testing to go to real pages"
expect{subject}.not_to raise_error(PageRecord::NotInputField) # TODO can we make it better?
end


Expand Down
116 changes: 0 additions & 116 deletions spec/shared_contexts.rb

This file was deleted.

14 changes: 11 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
Coveralls.wear!
require 'page_record'
require 'capybara'
require_relative './team'
require_relative './shared_contexts'
require_relative './shared_examples'
require 'capybara/dsl'
include Capybara::DSL

require_relative './support/test_app'
require_relative './support/team'
require_relative './support/shared_contexts'
require_relative './support/shared_examples'

Capybara.app = TestApp
Capybara.app_host = nil


RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
Expand Down
37 changes: 37 additions & 0 deletions spec/support/shared_contexts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
shared_context "page with single table with 3 records" do
before do
visit "/page-with-single-table-with-3-records"
end
end

shared_context "page with two tables with 3 records" do
before do
visit "/page-with-two-tables-with-3-records"
end
end


shared_context "page without records" do
before do
visit "/page-without-records"
end
end

shared_context "page with duplicate records" do
before do
visit "/page-with-duplicate-records"
end
end

shared_context "page one record in a form" do
before do
visit "/page-one-record-in-a-form"
end
end


shared_context "page one record" do
before do
visit "/page-one-record"
end
end
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions spec/support/test_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'sinatra/base'


class TestApp < Sinatra::Base

set :root, File.dirname(__FILE__)
set :raise_errors, true
# set :show_exceptions, false


get '/*' do
viewname = params[:splat].first # eg "some/path/here"
if File.exist?("#{settings.root}/views/#{viewname}.erb")
erb :"#{viewname}"
else
"can't find view #{viewname}"
end
end
end

if __FILE__ == $0
Rack::Handler::WEBrick.run TestApp, :Port => 8070
end
4 changes: 4 additions & 0 deletions spec/support/views/page-one-record-in-a-form.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<form data-team-id='1'>
<input data-attribute-for='name'>
<button data-action-for='create'>
</form>
3 changes: 3 additions & 0 deletions spec/support/views/page-one-record.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div data-team-id='1'>
<div data-attribute-for='name'></div>
</div>
8 changes: 8 additions & 0 deletions spec/support/views/page-with-duplicate-records.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<table>
<tr data-team-id='1'>
<td data-attribute-for='name'>Ajax</td>
</tr>
<tr data-team-id='1'>
<td data-attribute-for='name'>Ajax</td>
</tr>
</table>
17 changes: 17 additions & 0 deletions spec/support/views/page-with-single-table-with-3-records.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<table>
<tr data-team-id='1' class='champions_league'>
<td data-attribute-for='ranking'>1</td>
<td data-attribute-for='name'>Ajax</td>
<td data-attribute-for='points'>10</td>
</tr>
<tr data-team-id='2' class='champions_league'>
<td data-attribute-for='ranking'>2</td>
<td data-attribute-for='name'>PSV</td>
<td data-attribute-for='points'>8</td>
</tr>
<tr data-team-id='3'>
<td data-attribute-for='ranking'>3</td>
<td data-attribute-for='name'>Feijenoord</td>
<td data-attribute-for='points'>6</td>
</tr>
</table>
38 changes: 38 additions & 0 deletions spec/support/views/page-with-two-tables-with-3-records.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class='team-table'>
<table id='first-table'>
<tr data-team-id='1' class='champions_league'>
<td data-attribute-for='ranking'>1</td>
<td data-attribute-for='name'>Ajax</td>
<td data-attribute-for='points'>10</td>
</tr>
<tr data-team-id='2' class='champions_league'>
<td data-attribute-for='ranking'>2</td>
<td data-attribute-for='name'>PSV</td>
<td data-attribute-for='points'>8</td>
</tr>
<tr data-team-id='3' class='euro_league'>
<td data-attribute-for='ranking'>3</td>
<td data-attribute-for='name'>Feijenoord</td>
<td data-attribute-for='points'>6</td>
</tr>
</table>
</div>
<div class='team-table'>
<table id='second-table'>
<tr data-team-id='1' class='champions_league'>
<td data-attribute-for='ranking'>1</td>
<td data-attribute-for='name'>Ajax</td>
<td data-attribute-for='points'>10</td>
</tr>
<tr data-team-id='2' class='champions_league'>
<td data-attribute-for='ranking'>2</td>
<td data-attribute-for='name'>PSV</td>
<td data-attribute-for='points'>8</td>
</tr>
<tr data-team-id='3' class='euro_league'>
<td data-attribute-for='ranking'>3</td>
<td data-attribute-for='name'>Feijenoord</td>
<td data-attribute-for='points'>6</td>
</tr>
</table>
</div>
2 changes: 2 additions & 0 deletions spec/support/views/page-without-records.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<table>
</table

0 comments on commit 4301e5c

Please sign in to comment.