How do I fake OpenID login in RSpec user story/Cucumber when using open_id_authentication plugin
Date : March 29 2020, 07:55 AM
Hope that helps I've figured out a way, if you place this in your features/support/env.rb: ActionController::Base.class_eval do
private
def begin_open_id_authentication(identity_url, options = {})
yield OpenIdAuthentication::Result.new(:successful), identity_url, nil
end
end
Given /^I am logged in as "(.*)"$/ do |name|
user = User.find_by_name(user)
post '/session', :openid_url => user.identity_url
# Some assertions just to make sure our hack in env.rb is still working
response.should redirect_to('/')
flash[:notice].should eql('Logged in successfully')
end
|
RSpec vs Cucumber (RSpec stories)
Date : March 29 2020, 07:55 AM
To fix this issue If you haven't already, you might want to check out Dan North's excellent article, What's in a Story? as a starting point. We have two main uses for Cucumber stories. First, because the story form is very specific it helps focus the product owner's articulation of the features he wants built. This is the "token for a conversation" use of stories, and would be valuable whether or not we implemented the stories in code. Second, when the process is working well enough that we have complete stories before we begin writing the feature (more of an ideal that we strive for than a daily reality), you have your acceptance criteria spelled out clearly and you know exactly what and how much to build.
|
Is there an equivalent in RSpec to Cucumber's "Scenarios" or am I using RSpec the wrong way?
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I'm impressed at the brevity and usefulness of Cucumber's Scenarios, they're a great way to test a load of different cases. , Try the following approach. I like the way it turned out. describe StateDateMethods do
before :each do
@product = OpenStruct.new
@product.extend StateDateMethods
end
def parse_date(unparsed_date_value)
unless unparsed_date_value.nil?
DateTime.strptime(unparsed_date_value, '%m/%d/%Y')
end
end
context '#pre_order?' do
examples = [
# [visible_on, pre_order_on, for_sale_on] => method_result
{ :inputs => [nil, nil, nil], :expected => false },
{ :inputs => ['1/1/2001', nil, nil], :expected => false },
{ :inputs => ['1/1/2001', '1/1/2001', nil], :expected => true },
{ :inputs => ['1/1/2001', '1/2/2001', nil], :expected => true },
{ :inputs => ['1/1/2001', '1/1/2001', '1/2/2001'], :expected => false },
{ :inputs => ['1/1/2001', '1/1/2001', '1/1/3001'], :expected => true },
{ :inputs => ['1/1/2001', '1/1/3001', '1/2/3001'], :expected => false },
{ :inputs => ['1/1/3001', '1/1/3001', '1/2/3001'], :expected => false },
{ :inputs => ['1/1/2001', nil, '1/1/2001'], :expected => false },
{ :inputs => ['1/1/2001', nil, '1/1/3001'], :expected => false }
]
examples.each do |example|
inputs = example[:inputs]
it "should return #{example[:expected].inspect} when visible_on == #{inputs[0].inspect}, pre_order_on == #{inputs[1].inspect}, for_sale_on == #{inputs[2].inspect}" do
@product.visible_on = parse_date(inputs[0])
@product.pre_order_on = parse_date(inputs[1])
@product.for_sale_on = parse_date(inputs[2])
@product.pre_order?.should == example[:expected]
end
end
end
end
....F.....
Failures:
1) StateDateMethods#pre_order? should return false when visible_on == "1/1/2001", pre_order_on == "1/1/2001", for_sale_on == "1/2/2001"
Failure/Error: @product.pre_order?.should == example[:expected]
expected: false
got: true (using ==)
# ./spec_no_rails/state_date_methods_spec.rb:40:in `block (4 levels) in <top (required)>'
Finished in 0.38933 seconds
10 examples, 1 failure
Failed examples:
rspec ./spec_no_rails/state_date_methods_spec.rb:35 # StateDateMethods#pre_order? should return false when visible_on == "1/1/2001", pre_order_on == "1/1/2001", for_sale_on == "1/2/2001"
..........
Finished in 0.3889 seconds
10 examples, 0 failures
|
no such file to load -- rspec/matchers - rspec-rails, shoulda, cucumber, factory girl, Rails2.3.10
Date : March 29 2020, 07:55 AM
should help you out I ran into this same problem. After hunting down all binary rspec commands (several locations), I belatedly realized that the 1.3.2 branch of RSPEC titles its binary "spec" and not "rspec". So the correct commands was always "bundle exec spec spec/models/..." Putting "rspec" meant that bundler failed to find it in my current rvm/gemset and went searching through my entire path, eventually coming up with an /opt/local/bin copy that belonged to an rspec2.x install.
|
Why does guard start spork both for rspec and cucumber even if I wanted to start it only for rspec using groups?
Date : March 29 2020, 07:55 AM
around this issue You must disable Cucumber in Spork in the RSpec group and the other way around: specs :specs
guard :spork, :cucumber => false do
# ...
end
end
specs :features
guard 'spork', :rspec => false do
# ...
end
end
|