Skip to content

Commit

Permalink
Refactored specs to make more readable as well as removing non essent…
Browse files Browse the repository at this point in the history
…ai specs.
  • Loading branch information
baphled committed Aug 5, 2010
1 parent 15a62cb commit 95fc9b0
Showing 1 changed file with 52 additions and 44 deletions.
96 changes: 52 additions & 44 deletions spec/helpers/projects_helper_spec.rb
@@ -1,64 +1,72 @@
require 'spec_helper'

# @TODO Refactor the signature to make it more expressive
def setup_features unique = true
stories = []
3.times do |value|
scenario = (unique)? "something thats unique#{value}" : "something thats not unique"
stories << mock_model(Story,:scenario => scenario)
end

@feature.stub!(:stories).and_return stories
@feature_import = [{:file => 'foo', :feature => @feature}]
end

describe ProjectsHelper do
before(:each) do
@feature = stub_model(Feature).as_null_object
end

describe "#has_duplicate_feature?(:list)" do
context "When there a single feature are no duplicate scenario's" do
before(:each) do
stories = []
3.times { |value| stories << mock_model(Story,:scenario => "something thats unique#{value}")}
@feature.stub!(:stories).and_return stories
@feature_import = [{:file => 'foo', :feature => @feature}]
end

it "should return true" do
helper.has_duplicate_feature?('foo',@feature_import).should be_false
end
end
describe "#has_duplicate_feature?(:list)" do

context "When there a single feature are duplicate scenario's" do
before(:each) do
@stories = []
3.times { |value| @stories << mock_model(Story,:scenario => "something thats not unique")}
@feature.stub!(:stories).and_return @stories
@feature_import = [{:file => 'foo', :feature => @feature}]
end

it "should return false" do
helper.has_duplicate_feature?('foo', @feature_import).should be_true
end
end

context "When there are multiple features which have scenarios that are duplicate" do
before(:each) do
story = mock_model(Story,:scenario => "something thats not unique")
@feature.stub!(:stories).and_return [story]
@feature_import = [{:file => 'foo', :feature => @feature}, {:file => 'bar', :feature => @feature}]
context "a single feature" do

context "a single feature with no duplicate scenario's" do
before(:each) do
setup_features
end

it "returns true" do
helper.has_duplicate_feature?('foo',@feature_import).should be_false
end
end

it "should return true" do
helper.has_duplicate_feature?('bar', @feature_import).should be_true

context "a single feature with duplicate scenario's" do
before(:each) do
setup_features false
end

it "should return false" do
helper.has_duplicate_feature?('foo', @feature_import).should be_true
end
end
end

context "When there are multiple features which don't have scenarios that are duplicate" do
before(:each) do
story = mock_model(Story,:scenario => "something thats different")
newFeature = mock_model(Feature).as_null_object
newFeature.stub!(:stories).and_return [story]
@feature_import = [{:file => 'foo', :feature => @feature}, {:file => 'bar', :feature => newFeature}]
context "mutlple features" do

context "with duplicate scenarios" do
before(:each) do
setup_features false
end

it "returns true" do
helper.has_duplicate_feature?('foo', @feature_import).should be_true
end
end

it "should return false" do
helper.has_duplicate_feature?('foo', @feature_import).should be_false

context "with no duplicates" do
before(:each) do
setup_features
end

it "returns false" do
helper.has_duplicate_feature?('foo', @feature_import).should be_false
end
end
end
end
describe "#has_duplicate_feature_name?(:list)" do

describe "#has_duplicate_feature_name?(:list)" do
before(:each) do
@feature.stub!(:path).and_return "#{RAILS_ROOT}/spec/fixtures/features/sample_one.feature"
end
Expand Down

0 comments on commit 95fc9b0

Please sign in to comment.