mattscilipoti-model_steps 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/model_steps/step_definitions.rb +58 -39
- metadata +34 -14
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "mattscilipoti-model_steps"
|
8
8
|
gem.summary = %Q{Model Steps for cucumber}
|
9
|
-
gem.description = %Q{
|
9
|
+
gem.description = %Q{Step Definitions for cucumber which support ActiveRecord Models}
|
10
10
|
gem.email = "matt@scilipoti.name"
|
11
11
|
gem.homepage = "http://github.com/mattscilipoti/mattscilipoti-model_steps"
|
12
12
|
gem.authors = ["Matt Scilipoti"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Cucumber::Ast::Table.class_eval do
|
2
2
|
def is_date_column?(column_name)
|
3
|
-
column_name.columnify =~ /( at|_at|time|date)$/
|
3
|
+
column_name.columnify =~ /( at|_at|time|date)$/i
|
4
4
|
end
|
5
5
|
|
6
6
|
def chronic_parsable_columns
|
@@ -55,7 +55,7 @@ Then /^I should see (\d+) (\D+)$/ do |expected_count, requested_model|
|
|
55
55
|
|
56
56
|
end
|
57
57
|
|
58
|
-
Then /^I should see (?:these|the following) (\D+):$/ do |requested_model, table|
|
58
|
+
Then /^I should see (?:these|this|the following) (\D+):$/ do |requested_model, table|
|
59
59
|
# table is a Cucumber::Ast::Table
|
60
60
|
table.map_chronic_columns!
|
61
61
|
#WORKAROUND: why does table.diff! expect Trouble to be nil (vs. '')?
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
#Given the following Camera Events exist:
|
77
77
|
#Note: use ((?!.*should) to avoid conflicts with
|
78
78
|
# Given the following Camera Events should exist:
|
79
|
-
Given /^(?:these|the following) (?!.*should)(.+) exist:$/ do |requested_model, table|
|
79
|
+
Given /^(?:these|this|the following) (?!.*should)(.+) exist:$/ do |requested_model, table|
|
80
80
|
|
81
81
|
# table is a Cucumber::Ast::Table
|
82
82
|
model = requested_model_to_model(requested_model)
|
@@ -89,16 +89,7 @@ Given /^(?:these|the following) (?!.*should)(.+) exist:$/ do |requested_model, t
|
|
89
89
|
|
90
90
|
model_params = requested_params_to_model_params(requested_params, model)
|
91
91
|
|
92
|
-
model_under_test = Factory.create(model_to_factory_symbol(
|
93
|
-
|
94
|
-
if model_under_test.is_a?(ImportSession)
|
95
|
-
Traffipax.deprecated("special fixture code for 'the following Import Sessions exist'", 'only until ImportSession no longer has ImportSteps') unless ImportSession.new.respond_to?('import_steps')
|
96
|
-
trouble = model_params[:trouble]
|
97
|
-
#ensure last step has proper status
|
98
|
-
#TODO: this is a smell. We are bypassing proper operation. Is this test appropriate?
|
99
|
-
model_under_test.current_step.update_attributes!(:started_at => model_under_test.started_at, :completed_at => model_under_test.completed_at)
|
100
|
-
model_under_test.current_step.trouble = trouble if trouble
|
101
|
-
end
|
92
|
+
model_under_test = Factory.create(model_to_factory_symbol(requested_model), model_params)
|
102
93
|
|
103
94
|
model_under_test
|
104
95
|
end
|
@@ -167,7 +158,7 @@ end
|
|
167
158
|
#Given ModelA has the following existing ModelB's (see table)
|
168
159
|
# Finds the ModelB's which match the conditions
|
169
160
|
# And assigns themto ModelA.association
|
170
|
-
Given /^(\D+):(.+) has (?:these|the following) existing (\D+):$/ do |requested_model, default_identifier, requested_association_name, table|
|
161
|
+
Given /^(\D+):(.+) has (?:these|this|the following) existing (\D+):$/ do |requested_model, default_identifier, requested_association_name, table|
|
171
162
|
association_quantity = table.rows.size
|
172
163
|
|
173
164
|
map_table_columns!(table)
|
@@ -366,12 +357,12 @@ end
|
|
366
357
|
#Assumes:
|
367
358
|
# * Header = method name
|
368
359
|
# * the first column in each row is the default identifier for that row.
|
369
|
-
Then /^(?:these|the following) (.+) should exist:$/ do |requested_model, table|
|
360
|
+
Then /^(?:these|this|the following) (.+) should exist:$/ do |requested_model, table|
|
370
361
|
# table is a Cucumber::Ast::Table
|
371
362
|
model_klass = requested_model_to_model(requested_model)
|
372
363
|
|
373
364
|
models_to_verify = requested_models(requested_model)
|
374
|
-
assert_models(
|
365
|
+
assert_models(models_to_verify, table)
|
375
366
|
end
|
376
367
|
|
377
368
|
Then /^there should be (\d*) (.*)$/ do |cnt, requested_model|
|
@@ -386,17 +377,38 @@ end
|
|
386
377
|
#end
|
387
378
|
|
388
379
|
#Then Location:L1 should have the following Pings
|
380
|
+
#Or
|
381
|
+
#Then Location:L1 should have these attributes
|
389
382
|
#Works against actual models (instead of view)
|
390
383
|
#Verifies model count and each method in each row.
|
391
384
|
#Assumes:
|
392
385
|
# * Header = method name
|
393
386
|
# * the first column in each row is the default identifier for that row.
|
394
|
-
Then /^(\w+):(.+) should have (?:these|the following
|
387
|
+
Then /^(\w+):(.+) (?!.not|NOT)should have (?:these|this|the following) (.+):$/ do |requested_model, default_identifier, association, table|
|
395
388
|
# table is a Cucumber::Ast::Table
|
396
389
|
model_under_test = requested_model_with_identifier_to_model_instance(requested_model, default_identifier)
|
390
|
+
if association == 'attributes'
|
391
|
+
table.hashes.first.each do |attribute, expected_value|
|
392
|
+
model_under_test.send(attribute).to_s.should == expected_value
|
393
|
+
end
|
394
|
+
else
|
395
|
+
associated_models = model_under_test.send(association.underscore)
|
396
|
+
assert_models(associated_models, table)
|
397
|
+
end
|
398
|
+
end
|
397
399
|
|
398
|
-
|
399
|
-
|
400
|
+
Then /^(\w+):(.+) should (?:not|NOT) have (?:these|this|the following) (.+):$/ do |requested_model, default_identifier, association, table|
|
401
|
+
# table is a Cucumber::Ast::Table
|
402
|
+
model_under_test = requested_model_with_identifier_to_model_instance(requested_model, default_identifier)
|
403
|
+
|
404
|
+
if association == 'attributes'
|
405
|
+
table.hashes.first.each do |attribute, expected_value|
|
406
|
+
model_under_test.send(attribute).to_s.should_not == expected_value
|
407
|
+
end
|
408
|
+
else
|
409
|
+
associated_models = model_under_test.send(association.underscore)
|
410
|
+
assert_models(associated_models, table, :should_not)
|
411
|
+
end
|
400
412
|
end
|
401
413
|
|
402
414
|
#Then ModelA should have 1 ModelB
|
@@ -416,13 +428,16 @@ private
|
|
416
428
|
#Assumes:
|
417
429
|
# * Header = method name
|
418
430
|
# * the first column in each row is the default identifier for that row.
|
419
|
-
def assert_models(table,
|
420
|
-
expected_models.
|
421
|
-
model_klass = expected_models.first && expected_models.first.class.base_class rescue expected_models.first.class #support non-AR models
|
431
|
+
def assert_models(expected_models, table, should_not = false)
|
432
|
+
model_klass = expected_models.first && expected_models.first.class.base_class rescue expected_models.first.class
|
422
433
|
|
423
434
|
map_table_columns!(table)
|
424
435
|
rows = map_table_headers(table).hashes
|
425
|
-
|
436
|
+
if should_not
|
437
|
+
expected_models.count.should_not == rows.size
|
438
|
+
else
|
439
|
+
expected_models.count.should == rows.size
|
440
|
+
end
|
426
441
|
|
427
442
|
first_column_name = table.headers[0]
|
428
443
|
|
@@ -434,26 +449,30 @@ def assert_models(table, *expected_models)
|
|
434
449
|
#find the model for this row
|
435
450
|
model_under_test = expected_models.detect {|model| model.send(first_column_name).to_s == default_identifier }
|
436
451
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
if actual.is_a?(ActiveRecord::Base)
|
441
|
-
#if AR model, compare against value of default_identifier_column
|
442
|
-
actual = actual.send(actual.class.default_identifier_column)
|
443
|
-
end
|
452
|
+
unless should_not
|
453
|
+
model_under_test.should_not be_nil
|
454
|
+
end if
|
444
455
|
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
actual.
|
449
|
-
|
450
|
-
|
456
|
+
if model_under_test
|
457
|
+
#compare model with expectations
|
458
|
+
requested_params.each do |attribute_name, expected_value|
|
459
|
+
actual = model_under_test.send(attribute_name)
|
460
|
+
if actual.is_a?(ActiveRecord::Base)
|
461
|
+
actual = actual.send(actual.class.default_identifier_column)
|
462
|
+
end
|
463
|
+
if should_not
|
464
|
+
err_msg = "Expected ##{attribute_name} for '#{model_klass.name}:#{default_identifier}'\n\t to NOT have: '#{expected_value}'\n\tbut was: '#{actual}'\n * Expectations: #{requested_params.inspect} \n * #{model_klass.name}:#{default_identifier}: #{model_under_test.inspect}.\n\n"
|
465
|
+
actual.to_s.should_not eql(expected_value), err_msg
|
466
|
+
else
|
467
|
+
err_msg = "Expected ##{attribute_name} for '#{model_klass.name}:#{default_identifier}'\n\t to be: '#{expected_value}'\n\tbut was: '#{actual}'\n * Expectations: #{requested_params.inspect} \n * #{model_klass.name}:#{default_identifier}: #{model_under_test.inspect}.\n\n"
|
468
|
+
actual.to_s.should eql(expected_value), err_msg
|
469
|
+
end
|
451
470
|
end
|
452
|
-
|
453
471
|
end
|
454
472
|
end
|
455
473
|
end
|
456
474
|
|
475
|
+
|
457
476
|
def requested_model_with_identifier_to_model_instance(requested_model, default_identifier)
|
458
477
|
model = requested_model_to_model(requested_model)
|
459
478
|
model_under_test = model.find_by_default_identifier!(default_identifier)
|
@@ -570,7 +589,7 @@ def map_table_header(header)
|
|
570
589
|
#TODO: associations should be underscore'd
|
571
590
|
# mapped_header = header.columnify
|
572
591
|
mapped_header = header
|
573
|
-
mapped_header.sub!('#', 'Number')
|
592
|
+
# mapped_header.sub!('#', 'Number')
|
574
593
|
case header
|
575
594
|
when 'printer'
|
576
595
|
mapped_header = 'printer_prefix'
|
@@ -692,7 +711,7 @@ def requested_params_to_model_params(requested_params, model)
|
|
692
711
|
association_names = model.reflect_on_all_associations.collect &:name
|
693
712
|
|
694
713
|
mapped_params = {}
|
695
|
-
requested_params.each {|header, value| mapped_params[header
|
714
|
+
requested_params.each {|header, value| mapped_params[header] = value}
|
696
715
|
|
697
716
|
association_params = mapped_params.reject { |param_name, value| !association_names.include?(ModelSteps::Inflector.param_to_association_name(param_name)) }
|
698
717
|
association_params.each do |param_name, value|
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mattscilipoti-model_steps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Matt Scilipoti
|
@@ -9,30 +15,38 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-05-14 00:00:00 -04:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: micronaut
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
23
32
|
version: "0"
|
24
|
-
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
36
|
name: cucumber
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
30
40
|
requirements:
|
31
41
|
- - ">="
|
32
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
33
46
|
version: "0"
|
34
|
-
|
35
|
-
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Step Definitions for cucumber which support ActiveRecord Models
|
36
50
|
email: matt@scilipoti.name
|
37
51
|
executables: []
|
38
52
|
|
@@ -65,21 +79,27 @@ rdoc_options:
|
|
65
79
|
require_paths:
|
66
80
|
- lib
|
67
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
68
83
|
requirements:
|
69
84
|
- - ">="
|
70
85
|
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
71
89
|
version: "0"
|
72
|
-
version:
|
73
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
74
92
|
requirements:
|
75
93
|
- - ">="
|
76
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
77
98
|
version: "0"
|
78
|
-
version:
|
79
99
|
requirements: []
|
80
100
|
|
81
101
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.3.
|
102
|
+
rubygems_version: 1.3.7
|
83
103
|
signing_key:
|
84
104
|
specification_version: 3
|
85
105
|
summary: Model Steps for cucumber
|