Class: SpreeEssentials::IntegrationCase

Inherits:
ActiveSupport::TestCase
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/spree_essentials/testing/integration_case.rb

Instance Method Summary collapse

Instance Method Details

#assert_flash(key, text) ⇒ Object

Asserts the proper flash message

assert_flash :notice, "Post was successfully saved!"
assert_flash :error, "Oh No, bad things happened!"


48
49
50
51
52
# File 'lib/spree_essentials/testing/integration_case.rb', line 48

def assert_flash(key, text)
  within(".flash.#{key}") do
    assert_seen(text)
  end
end

#assert_meta(tag, text) ⇒ Object

Asserts meta tags have proper content

assert_meta :description, "So let me tell you about this one time..."
assert_meta :keywords, "seo, is, fun, jk."


67
68
69
70
# File 'lib/spree_essentials/testing/integration_case.rb', line 67

def assert_meta(tag, text)
  tag = find(:xpath, "//head/meta[@name='#{tag.to_s}']")
  assert_equal text, tag.native.attribute("content")
end

#assert_seen(text, opts = {}) ⇒ Object

An assertion for ensuring content has made it to the page.

assert_seen "Site Title"
assert_seen "Peanut Butter Jelly Time", :within => ".post-title h1"


32
33
34
35
36
37
38
39
40
41
# File 'lib/spree_essentials/testing/integration_case.rb', line 32

def assert_seen(text, opts={})
  msg = "Should see `#{text}`"
  if opts[:within]
    within(opts[:within]) do
      assert has_content?(text), msg + " within #{opts[:within]}"
    end
  else
    assert has_content?(text), msg
  end
end

#assert_title(title) ⇒ Object

Asserts the proper browser title

assert_title "My Site - Is super cool"


58
59
60
# File 'lib/spree_essentials/testing/integration_case.rb', line 58

def assert_title(title)
  assert_seen title, :within => "head title"
end

#spreeObject

By defining this we don’t need to depend on spree, just spree_core since the included url helper lives in the spree root



23
24
25
# File 'lib/spree_essentials/testing/integration_case.rb', line 23

def spree
  Spree::Core::Engine.routes.url_helpers
end