rspec

Rspec doesn't see my model Class. uninitialized constant error

梦想与她 提交于 2019-12-20 08:31:27
问题 I'm writing tests on Rspec for my models in Ruby on Rails application. And I receive this error while starting 'rspec spec' command: /spec/models/client_spec.rb:4:in `<top (required)>': uninitialized constant Client (NameError) I use Rails 4.0.0 and Ruby 2.0.0 Here is my client_spec.rb: require 'spec_helper' describe Client do it 'is invalid without first_name', :focus => true do client = Client.new client.should_not be_valid end end And Gemfile: source 'https://rubygems.org' # Bundle edge

How to find which rspec test is taking so long

百般思念 提交于 2019-12-20 08:16:20
问题 One (or a couple) of our tests are taking forever and we'd like to optimize them. We have say 1000 tests so it's impractical for me to go through run each file. Is there an easy to way to find the slow ones? This is rspec 1.3 回答1: In RSpec 2 and 3, you can use the --profile flag or add --profile to your .rspec file. This will track the top 10 slowest examples. For RSpec 1, you can use --format o with spec command. It shows a text-based progress bar with profiling of 10 slowest examples. For

How to make Capybara check for visibility after some JS has run?

懵懂的女人 提交于 2019-12-20 08:13:23
问题 After loading a page I have code that runs and hides and shows various items based on data returned by an xhr. My integration test looks something like this: it "should not show the blah" do page.find('#blah').visible?.should be_true end When I manually go to the page in the context this test runs, #blah is not visible as I expect. I suspect that Capybara is looking at the initial state of the page (invisible in this case), evaluating the state of the DOM and failing the test before the JS

How to make Capybara check for visibility after some JS has run?

痞子三分冷 提交于 2019-12-20 08:12:35
问题 After loading a page I have code that runs and hides and shows various items based on data returned by an xhr. My integration test looks something like this: it "should not show the blah" do page.find('#blah').visible?.should be_true end When I manually go to the page in the context this test runs, #blah is not visible as I expect. I suspect that Capybara is looking at the initial state of the page (invisible in this case), evaluating the state of the DOM and failing the test before the JS

RSpec controller testing - blank response.body

狂风中的少年 提交于 2019-12-20 08:09:08
问题 I am stuck with a problem when testing my controllers with RSpec - the response.body call always returns an empty string. In browser everything renders correctly, and cucumber feature tests seem to get it right, but RSpec fails each and every time. Other expectations on the response object, such as response.should render_template('index') pass without any problems. Have any of you encountered this problem before? Perhaps the response html can be obtained in some other way? As for versions,

Can I set an expectancy on should_receive and have it execute the original code?

ⅰ亾dé卋堺 提交于 2019-12-20 07:22:26
问题 I have something like: value = nil if some_condition value =my_object.do_stuff() end And in my test, I have the follwing: MyObject.any_instance.should_receive(:do_stuff) However, I'd like to just test that the method was called, and have it execute the original code. I'd like to NOT have to do it like: MyObject.any_instance.should_receive(:do_stuff).and_return(:some_dummy_value) Is there a way of doing that? 回答1: There is and_call_original method: MyObject.any_instance.should_receive(:do

Undefined local variable or Method - Testing Puppet Modules using Beaker

你。 提交于 2019-12-20 04:41:56
问题 I'm quite new to all of this. I am trying to test out a puppet module using Beaker. I keep getting this: NoMethodError: undefined method `describe' for #Beaker::TestCase:0x007fd6f95e6460 /Users/user1/beaker/Puppet/puppet-files/spec/classes/unit_spec.rb:3 /Users/user1/.rvm/gems/ruby-2.2.7/gems/beaker-3.24.0/bin/beaker:9 /Users/user1/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15 /Users/user1/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15. This is the command that I'm running - "beaker -

Undefined local variable or Method - Testing Puppet Modules using Beaker

只谈情不闲聊 提交于 2019-12-20 04:41:02
问题 I'm quite new to all of this. I am trying to test out a puppet module using Beaker. I keep getting this: NoMethodError: undefined method `describe' for #Beaker::TestCase:0x007fd6f95e6460 /Users/user1/beaker/Puppet/puppet-files/spec/classes/unit_spec.rb:3 /Users/user1/.rvm/gems/ruby-2.2.7/gems/beaker-3.24.0/bin/beaker:9 /Users/user1/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15 /Users/user1/.rvm/gems/ruby-2.2.7/bin/ruby_executable_hooks:15. This is the command that I'm running - "beaker -

RSpec matcher that checks collection to include item that satisfies lambda

我们两清 提交于 2019-12-20 04:40:09
问题 I am a bit at a loss as to how to write a RSpec 3.2.x spec that checks wether a list contains at least one item that satisfies a condition. Here is an example: model = Invoice.new model.name = 'test' changes = model.changes expect(changes).to include { |x| x.key == 'name' && x.value == 'test' } There will be other (automated) changes in the changes list too so I don't want to verify that there is only one specific change and I also don't want to rely on ordering expect(changes.first)... so I

Why do I get puppet-rspec 'class does not exist' when it does?

感情迁移 提交于 2019-12-20 04:34:58
问题 I setup a new puppet demo module with the following Gemfile and it worked as expected when I ran a simple puppet-rspec test. Gemfile source 'https://rubygems.org' if puppetversion = ENV['PUPPET_GEM_VERSION'] gem 'puppet', puppetversion, :require => false else gem 'puppet', '3.7.5' end gem 'metadata-json-lint' gem 'puppetlabs_spec_helper', '>= 0.1.0' gem 'puppet-lint', '>= 1.0.0' gem 'facter', '>= 1.7.0' gem 'rspec-puppet-facts' # rspec must be v2 for ruby 1.8.7 if RUBY_VERSION >= '1.8.7' and