Module: MundoPepino::Implementations

Included in:
MundoPepino
Defined in:
lib/mundo_pepino/implementations.rb

Instance Method Summary collapse

Instance Method Details

#given_or_when_i_do_a_page_request(params) ⇒ Object



84
85
86
# File 'lib/mundo_pepino/implementations.rb', line 84

def given_or_when_i_do_a_page_request(params)
  do_visit params[:page].to_unquoted.to_page
end


88
89
90
91
92
93
94
# File 'lib/mundo_pepino/implementations.rb', line 88

def given_or_when_i_follow_the_link(params)
  if params[:selector].blank?
    click_link params[:link]
  else
    click_link_within params[:selector], params[:link]
  end
end

#given_resource_has_many_children(params) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/mundo_pepino/implementations.rb', line 65

def given_resource_has_many_children(params)
  children_model = convert_to_model(params[:children_field])
  last_mentioned_resources(params[:model], params[:name]) do |resource|
    attribs = names_for_simple_creation(children_model, 
      (params[:number_of_children] || '1').to_number, params[:children_names],
      parent_options(resource, children_model, params[:children_field]))
    add_resource children_model, attribs, :force_creation => params[:children_names].nil?
  end
end

#given_resource_has_many_children_from_step_table(params) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/mundo_pepino/implementations.rb', line 75

def given_resource_has_many_children_from_step_table(params)
  children_model = convert_to_model(params[:children_field])
  last_mentioned_resources(params[:model], params[:name]) do |resource|
    options = parent_options(resource, children_model, params[:children_field])
    options[:model] = children_model
    add_resource children_model, translated_hashes(params[:step_table].raw, options)
  end
end

#given_resource_have_the_following_values_from_step_table(params) ⇒ Object

Params: :model (raw) (optional) :table :name (optional)



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/mundo_pepino/implementations.rb', line 52

def given_resource_have_the_following_values_from_step_table(params)
  params[:model] = last_mentioned.class.name.downcase if params[:model].nil?

  params[:table].hashes.each do |hash|
    hash.each_pair do |campo, valor|
      given_those_resources_have_value_in_field :model => params[:model],
                                                :name => params[:name],
                                                :field => campo,
                                                :value => valor
    end
  end
end

#given_those_resources_have_value_in_field(params) ⇒ Object

Params:

:model
:field
:value
:name (optional)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mundo_pepino/implementations.rb', line 28

def given_those_resources_have_value_in_field(params)
  if res = params[:name] ? [last_mentioned_of(params[:model], params[:name])] : last_mentioned_of(params[:model])

    if resource_not_respond_to_field?(res, params[:field]) && !resource_respond_to_relation_field?(res, params[:field])
      params.merge!(:children_field => params[:field], :children_names => params[:value])
      given_resource_has_many_children(params)
    else
      resources, field, values = resources_array_field_and_values(res, params[:field], params[:value])
      if field
        resources.each_with_index do |r, i|
          r.update_attribute field, real_value_for(values[i])
        end
        pile_up res
      else
        raise MundoPepino::FieldNotMapped.new(params[:field])
      end
    end
  end
end

#given_we_have_a_number_of_instances_called(params) ⇒ Object

Params:

:model (raw)
:number (f.e. "a", "three")
:name ("Foo") or :names ("Foo, Fu and Kunfu")


7
8
9
10
11
12
# File 'lib/mundo_pepino/implementations.rb', line 7

def given_we_have_a_number_of_instances_called(params)
  model = params[:model].to_unquoted.to_model || raise(ModelNotMapped.new(params[:model]))
  number = params[:number].to_number
  attribs = names_for_simple_creation(model, number, params[:name])
  add_resource(model, attribs, :force_creation => true)
end

#given_we_have_the_following_instances_from_step_table(params) ⇒ Object

Params:

:model (raw)
:table


17
18
19
20
21
# File 'lib/mundo_pepino/implementations.rb', line 17

def given_we_have_the_following_instances_from_step_table(params)
  model = convert_to_model(params[:model])
  add_resource model, translated_hashes(params[:table].raw, :model => model),
    :force_creation => true
end

#then_i_see_or_not_the_text(params) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/mundo_pepino/implementations.rb', line 96

def then_i_see_or_not_the_text(params)
  if params[:selector].blank?
    should_or_not_contain_text params
  else
    if defined?(Capybara)
      with_scope params[:selector] do
        should_or_not_contain_text params
      end
    else
      within params[:selector] do |content|
        should_or_not_contain_text content, params
      end
    end
  end
end

#then_resource_called_name_should_have_child(params) ⇒ Object



139
140
141
142
# File 'lib/mundo_pepino/implementations.rb', line 139

def then_resource_called_name_should_have_child(params)
  add_resource_from_database params[:model], params[:name]
  then_that_resource_should_have_child params
end

#then_resource_called_name_should_have_n_children(params) ⇒ Object



121
122
123
124
# File 'lib/mundo_pepino/implementations.rb', line 121

def then_resource_called_name_should_have_n_children(params)
  add_resource_from_database params[:model], params[:name]
  then_that_resource_should_have_n_children params
end

#then_resource_called_name_should_have_value_in_field(params) ⇒ Object



130
131
132
133
# File 'lib/mundo_pepino/implementations.rb', line 130

def then_resource_called_name_should_have_value_in_field(params)
  add_resource_from_database(params[:model], params[:name])
  then_that_resource_should_have_value_in_field params
end

#then_that_resource_should_have_child(params) ⇒ Object



144
145
146
# File 'lib/mundo_pepino/implementations.rb', line 144

def then_that_resource_should_have_child(params)
  last_mentioned_should_have_child(params[:children_field], params[:child_name])
end

#then_that_resource_should_have_n_children(params) ⇒ Object



126
127
128
# File 'lib/mundo_pepino/implementations.rb', line 126

def then_that_resource_should_have_n_children(params) 
  last_mentioned_should_have_n_children(params[:children_field], params[:number])
end

#then_that_resource_should_have_value_in_field(params) ⇒ Object



135
136
137
# File 'lib/mundo_pepino/implementations.rb', line 135

def then_that_resource_should_have_value_in_field(params)
  last_mentioned_should_have_value(params[:field], params[:value].to_real_value)
end

#then_we_have_a_number_of_instances_in_our_database(params) ⇒ Object

DB CHECKS



113
114
115
116
117
118
119
# File 'lib/mundo_pepino/implementations.rb', line 113

def then_we_have_a_number_of_instances_in_our_database(params)
  model = convert_to_model(params[:model])
  conditions = params[:name] && {:conditions => ["#{field_for(model)}=?", params[:name]]}
  resources = model.find(:all, conditions || {})
  resources.size.should == params[:number].to_number
  pile_up (resources.size == 1 ? resources.first : resources) if resources.size > 0
end