Skip to content

Commit

Permalink
Mass cleanup of specs, still need to give them a once over to make th…
Browse files Browse the repository at this point in the history
…em more readable and some basic housekeeping.
  • Loading branch information
baphled committed Aug 5, 2010
1 parent 95fc9b0 commit d8fcf6b
Show file tree
Hide file tree
Showing 31 changed files with 382 additions and 372 deletions.
1 change: 1 addition & 0 deletions spec/controllers/features_controller_spec.rb
Expand Up @@ -32,6 +32,7 @@
end
end

# @TODO Improve the speed of these specs. First step would be to improve the features_to_import? method
describe "POST, sync" do
before(:each) do
@project = Project.make
Expand Down
8 changes: 1 addition & 7 deletions spec/controllers/welcome_controller_spec.rb
Expand Up @@ -2,14 +2,8 @@

describe WelcomeController do

#Delete these examples and add some real ones
it "should use WelcomeController" do
controller.should be_an_instance_of(WelcomeController)
end


describe "GET 'index'" do
it "should be successful" do
it "makes a successful request" do
get 'index'
response.should be_success
end
Expand Down
1 change: 1 addition & 0 deletions spec/helpers/welcome_helper_spec.rb
@@ -1,5 +1,6 @@
require 'spec_helper'

# @TODO Remove spec as not needed
describe WelcomeHelper do

#Delete this example and add some real ones or delete this file
Expand Down
48 changes: 24 additions & 24 deletions spec/models/feature_file_spec.rb
Expand Up @@ -5,11 +5,11 @@
@feature_file = FeatureFile.new("#{RAILS_ROOT}/spec/blueprints.rb")
end

it "should be a child of the File object" do
it "extends the File object" do
@feature_file.should be_a File
end

context "an invalid feature file" do
context "invalid feature file" do
it "should be invalid" do
@feature_file.should be_invalid
end
Expand All @@ -20,94 +20,94 @@
@feature_file = FeatureFile.new "#{RAILS_ROOT}/features/plain/enhancements.feature"
end

it "should store scenario outlines" do
it "stores scenario outlines" do
@feature_file.scenarios.first.scenario.should contain 'When a user visits the site without JS enable we want to display a header notifying them that the site works best with JS'
end

it "should store the outlines steps" do
it "stores the outlines steps" do
@feature_file.scenarios.first.steps.should_not be_empty
end

it "should have a list of examples associated to it" do
it "has a list of examples associated to it" do
@feature_file.scenarios.first.example.should_not be_blank
end

it "should have a list of associated actions" do
it "has a list of associated actions" do
@feature_file.scenarios.first.example.actions.should_not be_empty
end

it "should story the actions in the expected format" do
it "the actions should be in the expected format" do
@feature_file.scenarios.last.example.actions.first.title.should == 'page'
end

it "should store the actions items" do
it "stores the actions items" do
@feature_file.scenarios.last.example.actions.last.items.should_not be_empty
end
end

context "a valid feature file" do
context "valid feature file" do
before(:each) do
@feature_file = FeatureFile.new("#{RAILS_ROOT}/spec/fixtures/test.feature")
end

it "should be a cucumber feature file" do
it "is a cucumber feature file" do
@feature_file.should_not be_invalid
end

it "should store the feature heading within the feature properties" do
it "has a feature that is a string" do
@feature_file.feature.should be_a String
end

it "should store the features in order heading" do
it "has the in order value as a string" do
@feature_file.in_order.should be_a String
end

it "should store the as a heading" do
it "stores the as a heading" do
@feature_file.as_a.should_not be_nil
end

it "should store the features i want heading" do
it "stores the features i want heading" do
@feature_file.i_want.should_not be_nil
end

it "should store the scenario's for the feature" do
it "stores the scenario's for the feature" do
@feature_file.scenarios.should_not be_nil
end

it "should contain a scenario" do
it "contains a scenario" do
@feature_file.scenarios.should_not be_nil
end

it "should contain a scenario with steps" do
it "contains a scenario with steps" do
@feature_file.scenarios.first.steps.should_not be_nil
end

it "should store the expected amount of steps" do
it "stores the expected amount of steps" do
@feature_file.scenarios.first.steps.count == 3
end

it "should have access to the files path" do
it "has access to the files path" do
@feature_file.path.should eql "#{RAILS_ROOT}/spec/fixtures/test.feature"
end

context "exporting the feature files information" do
it "return the features title" do
it "returns the features title" do
@feature_file.export.should be_a Feature
end

it "should return the in order property " do
it "returns the in order property " do
@feature_file.export.in_order.should_not be_nil
end

it "should return the as a property" do
it "returns the as a property" do
@feature_file.export.as_a.should be_a String
end

it "should return the i want property" do
it "returns the i want property" do
@feature_file.export.i_want.should be_a String
end

it "should return a list of stories" do
it "returns a list of stories" do
@feature_file.export.stories.should_not be_empty
end
end
Expand Down
90 changes: 49 additions & 41 deletions spec/models/feature_spec.rb
Expand Up @@ -12,62 +12,66 @@
@feature.path.should contain "#{RAILS_ROOT}/features/plain/most_used.feature"
end

it "should save if the feature location is valid" do
@feature.update_attribute(:path, "#{RAILS_ROOT}/features/plain/most_used.feature").should be_true
context "valid location" do
it "saves" do
@feature.update_attribute(:path, "#{RAILS_ROOT}/features/plain/most_used.feature").should be_true
end
end

it "should not save if the feature location is not valid" do
@feature.path = 'foo'
@feature.save.should_not be_true

context "invalid location" do
it "should not save if the feature location is not valid" do
@feature.path = 'foo'
@feature.save.should_not be_true
end
end

context "exporting features" do
context "displaying exported features" do

it "should display the 'Feature:' prefix" do
it "have a 'Feature:' prefix" do
@feature.export.should contain "Feature:"
end

it "should display the feature title" do
it "displays the title" do
@feature.export.should contain "Feature: #{@feature.title}"
end

it "should contain an in order line" do
it "contains an in order line" do
@feature.export.should contain "In order"
end

it "should contain the 'in order' contents" do
it "contains the 'in order' contents" do
@feature.export.should contain "In order #{@feature.in_order}"
end

it "should contain an 'as' line" do
it "contains an 'as' line" do
@feature.export.should contain "As"
end

it "should contain a 'as' contents" do
it "contains a 'as' contents" do
@feature.export.should contain "As #{@feature.as_a}"
end

it "should contain a 'i want' line" do
it "contains a 'i want' line" do
@feature.export.should contain "I want"
end

it "should contain a 'i want contents" do
it "contains a 'i want contents" do
@feature.export.should contain "I want #{@feature.i_want}"
end

it "should should have at least one scenario" do
it "contains at least one scenario" do
@feature.export.should contain "Scenario:"
end

it "should have a scenario for each story" do
it "has a scenario for each story" do
@feature.stories.each do |story|
if not story.steps.blank?
@feature.export.should contain "#{story.scenario}"
end
end
end

it "should display each stories steps" do
it "displays each stories steps" do
@feature.stories.each do |story|
if not story.steps.nil?
story.steps.each do |step|
Expand All @@ -82,17 +86,17 @@
@feature = FeatureFile.new("#{RAILS_ROOT}/features/plain/navigations.feature").export
end

it "should display the example heading" do
it "displays the example heading" do
@feature.export.should contain "Examples: #{@feature.stories.first.example.heading}"
end

it "should display the examples action headings" do
it "displays the examples action headings" do
@feature.stories.first.example.actions.each do |action|
@feature.export.should contain "| #{action.title} |"
end
end

it "should have items" do
it "has items" do
@feature.stories.first.example.actions.each do |action|
action.items.each do |item|
if item.title == ' '
Expand All @@ -107,38 +111,38 @@

end

context "checking the difference between a stored feature and the source file" do
context "comparing a source feature with the system" do
before(:each) do
@feature = FeatureFile.new("#{RAILS_ROOT}/features/plain/tag_cloud.feature").export
end

it "should be able to export a feature for comparison" do
it "has exported features" do
@feature.export.should_not be_empty
end

it "should store the system based feature in a temp file" do
it "stores the system based feature in a temp file" do
FileUtils.touch("#{RAILS_ROOT}/tmp/#{File.basename(@feature.path)}.tmp")
file = File.new("#{RAILS_ROOT}/tmp/#{File.basename(@feature.path)}.tmp", 'w')
file.write(@feature.export)
file.should_not == ''
end

it "should return true if there is a diff" do
it "returns true if there is a diff" do
@feature.update_attribute(:title, 'Something different')
@feature.is_diff?.should be_true
end

it "should return false if there is no diff" do
it "returns false if there is no diff" do
@feature.is_diff?.should be_false
end
end

context "finding for features that have not been added to the system yet" do
context "finding features that have not been added to the system yet" do
before(:each) do
Feature.stub!(:imports_found).with("#{RAILS_ROOT}").and_return [FeatureFile.new("#{RAILS_ROOT}/spec/fixtures/features/tag_cloud.feature").export]
end

it "should return a list of files to import" do
it "returns a list of files to import" do
Feature.imports_found("#{RAILS_ROOT}").should_not be_empty
end

Expand All @@ -154,42 +158,46 @@
@feature.stub!(:path).and_return "#{RAILS_ROOT}/spec/fixtures/features/tag_cloud.feature"
end

context "patching a feature file in dry-run mode" do
it "gets a patch of the changes" do
context "in dry-run mode" do
it "executes patch" do
@feature.should_receive(:patch)
@feature.sync(true)
end

context "it successfully synchronises a feature file" do
context "successfully synchronises" do
before(:each) do
@feature.stub!(:sync).and_return true
end

it "should return true" do
it "returns true" do
@feature.sync(true).should == true
end
end

context "it unsuccessfully synchronises a feature file" do
context "unsuccessfully synchronises" do
before(:each) do
@feature.stub!(:sync).and_return false
end

it "should return false" do
it "returns false" do
@feature.sync.should == false
end
end
end

context "patching a feature file" do
it "should return true" do
@feature.stub!(:sync).with(false).and_return true
@feature.sync(false).should == true
context "successful" do
it "returns true" do
@feature.stub!(:sync).with(false).and_return true
@feature.sync(false).should == true
end
end

it "should display false" do
@feature.stub!(:sync).with(false).and_return false
@feature.sync(false).should == false

context "unsuccessful" do
it "displays false" do
@feature.stub!(:sync).with(false).and_return false
@feature.sync(false).should == false
end
end
end
end
Expand Down

0 comments on commit d8fcf6b

Please sign in to comment.