rspec2

rspec: undefined local variable or method `be_true'

核能气质少年 提交于 2019-12-06 08:12:19
I am using rspec 2.4.0 and cucumber 0.6.4. I am running a simple scenario (for the sake of this question): Scenario: Simple Test When I test something with step definition: require 'rspec' require 'rspec/expectations' When /^I test something$/ do result = (1==1) result.should be_true end When I run this scenario I get the following problems: undefined local variable or method `be_true' for #<Object:0x1b3b424> (NameError) I am also using bundler to manage my dependencies. Am I doing something obviously wrong here? Regards, Mark From the cucumber documentation: To use RSpec’s 2.x.x expectations

Repeated test descriptions with RSpec for every user role

家住魔仙堡 提交于 2019-12-06 06:41:00
问题 Creating some controller tests with RSpec, I find myself repeating several test cases for every possible user role. For example describe "GET 'index'" do context "for admin user" do login_user("admin") it "has the right title" do response.should have_selector("title", :content => "the title") end end context "for regular user" do login_user("user") it "has the right title" do response.should have_selector("title", :content => "the title") end end end This is a simple example just to make my

Equality using OR in RSpec 2

若如初见. 提交于 2019-12-06 03:18:47
What is the correct way to write the following example? The player's score should equal 5 or 8. it "should equal 5 or 8" do player.score.should == 5 or 8 end Thanks! Tim 5 or 8 will produce result 5 all the time and not do what you expect. You can use Rspec's satisfy matcher. player.score.should satisfy {|s| [5,8].include?(s)} 来源: https://stackoverflow.com/questions/6474726/equality-using-or-in-rspec-2

How to mock/stub the config initializer hash in rails 3

对着背影说爱祢 提交于 2019-12-06 00:53:36
Environment : Rails 3.1.1 and Rspec 2.10.1 I am loading all my application configuration through an external YAML file. My initializer (config/initializers/load_config.rb) looks like this AppConfig = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV] And my YAML file sits under config/config.yml development: client_system: SWN b2c_agent_number: '10500' advocacy_agent_number: 16202 motorcycle_agent_number: '10400' tso_agent_number: '39160' feesecure_eligible_months_for_monthly_payments: 1..12 test: client_system: SWN b2c_agent_number: '10500' advocacy_agent_number: 16202 motorcycle

Rspec testing of counter_cache column's returning 0

霸气de小男生 提交于 2019-12-06 00:02:25
问题 For days now I have been trying to get to the bottom of what seam to be something that should be very easy to do... I am however still very new to the world of rails and ruby and I just cant work this one out... :p Anyway the problem I am having is that I have a number of :counter_cache columns in my model's, which are all working quite nicely when testing them manually. However I am wanting to do the TDD thing and I cant seam to test them in rspec for some unknown reason?? Anyway here is an

Rspec, test Gems

断了今生、忘了曾经 提交于 2019-12-05 21:34:58
I've developed a gem which is to use inside a model by adding acts_as_gmappable and it's possible to pass options in the declaration. Now that I want to write tests with Rspec, I'm stuck for all model related functions: check if geocoding was properly done check I create a proper json from all database entries etc ... I know how to do these inside a Rails app but definitly not for a gem. Any track? I managed to do this by reading the excellent book of Jose Valim: http://plataformatec.com.br/crafting-rails-applications/ He describes how he tests his gem using his engine builder: https://github

session object in rspec integration test

爱⌒轻易说出口 提交于 2019-12-05 21:04:07
问题 I am using rspec and capybara for integration testing. Is their a way to make session objects in request specs? I have a view page in which I use a session object to check its value to display selective content. The problem am facing is that I cannot create a session object in request spec. Here is an example of the view: <% if session[:role] == "Role" %> ---content--- <% else %> --content-- <% end %> And inside my request spec session[:role] = "Role" visit my_path But it throws me an error

rails3 rspec issue

蹲街弑〆低调 提交于 2019-12-05 19:50:44
I am trying out rails3. I am using railstutorial site to explore more about rails3; the tutorial is very good to begin with (I have minimal experience with rails2). I have an issue with rspec which is currently blocking my progress. I saw that the tutorial recommended using rspec2.0.0.beta.18 gem; I instead installed rspec2.0.0.beta.20 gem using bundle install However I find issues with this version of rspec My rspec for integration_test looks like: describe "LayoutLinks" do it "should have a About page at '/about'" do get '/about' response.should have_selector('h1', :content => "About Us")

How do I define sequences in FactoryGirlRails?

℡╲_俬逩灬. 提交于 2019-12-05 19:01:25
Previously in Factory girl, we could define sequences like so: # /spec/factories.rb FactoryGirl.define do # this is the sequence in question: sequence(:random_token) { Digest::MD5.hexdigest(rand.to_s) } factory :story do sequence(:title) { |n| "My Cool Story##{n}" } # Call the sequence here: token { Factory.next(:random_token) } description { "#{title} description"} end end Now, when I try that approach - I get a deprecation warning telling me: WARNING: FactoryGirl::Sequence#next is deprecated. Use #run instead. When I replace #next with #run, I get a no-method error. I can't find the new

Why after_commit not running even with use_transactional_fixtures = false

喜夏-厌秋 提交于 2019-12-05 12:05:57
问题 Transactional fixtures in rspec prevent after_commit from being called, but even when I disable them with RSpec.configure do |config| config.use_transactional_fixtures = false end The after_commit callback does not run. Here is a rails app with the latest rspec / rails that I have produced the issue on: git://github.com/sheabarton/after_commit_demo.git 回答1: One way around this is to trigger the commit callbacks manually. Example: describe SomeModel do subject { ... } context 'after_commit' do