Skip to content

Commit

Permalink
Changing The DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
arailsdemo committed Jan 30, 2011
1 parent b868706 commit 60fef5e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
16 changes: 8 additions & 8 deletions spec/integration/user/post_viewing_spec.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
require "spec_helper"

describe "Meet Capybara (non admin).", :integration => true do
context "He's crawling around our app." do
Scenario "Meet Capybara (non admin).", :integration => true do
Given "He's crawling around our app." do
let(:post1){ @post1 ||= Factory(:post) }
let(:post2){ @post2 ||= Factory(:post) }

before { post1; post2 }

context "When he visits the post index page," do
When "he visits the post index page," do
before { visit posts_url }

it "then he should see a listing of post titles" do
Then "he should see a listing of post titles" do
page.should have_content post1.title
page.should have_content post2.title
end

it "and the posts should be in div.postShow" do
And_ "the posts should be in div.postShow" do
within(:xpath, '//div[@class="postShow"][1]') do
page.should have_content(post1.title)
end
Expand All @@ -25,18 +25,18 @@
end
end

context "When Capybara clicks on the 'Show' link for the first post," do
When "Capybara clicks on the 'Show' link for the first post," do
before do
find(:xpath, "//a[@href=\'#{post_path(post1.sequence)}\']").click
end

it "then he should see the show page" do
Then "he should see the show page" do
save_and_open_page
page.should have_content post1.title
current_path.should == "/posts/#{post1.sequence}"
end

it "and he shouldn't see an edit link" do
And_ "he shouldn't see an edit link" do
page.should have_no_selector 'a', :text => 'Edit'
end
end
Expand Down
9 changes: 8 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
config.include Stubs

config.include Stubs, :type => :view, :example_group => {
:file_path => config.escaped_path(%w[spec (views|helpers)])
}

config.include MySpec::IntegrationHelper, :type => :integration, :example_group => {
:file_path => config.escaped_path(%w[spec integration])
}
end
end

Expand Down
29 changes: 29 additions & 0 deletions spec/support/integration_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module MySpec
module IntegrationHelper
def self.included(base)
base.class_eval do
include DSLHelper
end
end
end

module DSLHelper
def self.included(base)
class << base
alias_method :Given, :describe
alias_method :And, :describe
alias_method :When, :describe
end

RSpec::Core::ExampleGroup.class_eval do
define_example_method :Then
define_example_method :And_
define_example_method :Or
end
end
end
end

class Object
alias_method :Scenario, :describe
end
2 changes: 0 additions & 2 deletions spec/views/posts/_form.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "spec_helper"

describe "posts/_form.html.haml" do
include Stubs

before do
view.stub :javascript
stub_template "shared/_error_messages.html.haml" => 'error messages'
Expand Down

0 comments on commit 60fef5e

Please sign in to comment.